InputManager causing UI events to fire twice
See original GitHub issueGreetings,
I’ve recently started running into an issue that causes my button events to fire twice.
To allow users to drag and drop objects to move them around, I use the IInputHandler interface to detect user input. This requires the InputManager and a call to it’s AddGlobalListener
method. The implementation worked great, but ever since I’ve been trying to figure out why my button events would fire twice (not always, just most of the time).
I’m using a world space canvas with simple button On Click events (defined in the Unity Inspector), which are handled by the HoloLensInputModule.
After digging around, it appears that the InputManager handles UI input as well, but doesn’t prevent the main event system from calling the same method. As such, I’m left with the below two stacktraces. Despite the frame difference, this is the result of one tap gesture:
Rotating 90 degrees (frame 605).
UnityEngine.Debug:LogFormat(String, Object[])
MoveProjectMenu:RotateProject(Single) (at Assets/Scripts/UI/MoveProjectMenu.cs:217)
UnityEngine.EventSystems.ExecuteEvents:ExecuteHierarchy(GameObject, BaseEventData, EventFunction`1)
HoloToolkit.Unity.InputModule.InputManager:HandleEvent(BaseEventData, EventFunction`1) (at Assets/HoloToolkit/Input/Scripts/InputManager.cs:256)
HoloToolkit.Unity.InputModule.InputManager:RaiseInputClicked(IInputSource, UInt32, Int32) (at Assets/HoloToolkit/Input/Scripts/InputManager.cs:352)
HoloToolkit.Unity.InputModule.GesturesInput:OnTappedEvent(InteractionSourceKind, Int32, Ray) (at Assets/HoloToolkit/Input/Scripts/InputSources/GesturesInput.cs:154)
UnityEngine.VR.WSA.Input.GestureRecognizer:InvokeTapEvent(InteractionSourceKind, Ray, Int32)
Rotating 90 degrees (frame 620).
UnityEngine.Debug:LogFormat(String, Object[])
MoveProjectMenu:RotateProject(Single) (at Assets/Scripts/UI/MoveProjectMenu.cs:217)
UnityEngine.EventSystems.EventSystem:Update()
I found a somewhat related issue (https://github.com/Microsoft/HoloToolkit-Unity/issues/658), but it didn’t help since both calls were handled by the HoloToolkit, allowing the user to set and read the used flag.
I also found a thread on the HoloLens forums (https://forums.hololens.com/discussion/6999/ui-button-on-click-event-firing-twice), where a user seemingly ‘solved’ the issue by increasing certain intervals. I did try out this workaround, but without any positive results.
Apologies if I’m misunderstanding the big picture of the InputManager. Any alternatives or solutions are very much appreciated.
Issue Analytics
- State:
- Created 6 years ago
- Comments:14 (5 by maintainers)
Top GitHub Comments
Your God’s son .Saved me man
@StephenHodgson Thanks for having a look.
I kind of wished there was more control over the InputManager, such as defining what the InputManager does and doesn’t handle. I’ll remove the default HoloLens input components and deal with the fact that scrolling ScrollRect components is not currently supported.
@connorjsmith As I’ve stated previously, I’ve not implemented this interface. My methods are bound to the uGUI Button OnClick event.