question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

InputManager causing UI events to fire twice

See original GitHub issue

Greetings,

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:closed
  • Created 6 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
veerpalkcommented, Sep 28, 2018

@Errors4l, I took a look last night and simply removed the HoloLensInputModule and HoloLensInput on the EventSystem and your project worked just fine for me. image

Your God’s son .Saved me man

1reaction
Errors4lcommented, Jun 3, 2017

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

InputManager causing UI events to fire twice #683
I've recently started running into an issue that causes my button events to fire twice. To allow users to drag and drop objects...
Read more >
Button OnClick Event is firing twice
The first event is fired when I no longer press the mouse Button on the Button, so its a mouseUp event that fires...
Read more >
UI Button On Click() event firing twice
With the script, I am able to airtap on UI Buttons. However, my event handler (attached to On Click through the Inspector) gets...
Read more >
Why are my Player Input Unity Events started twice?
No, it's just one player. The player is spawned automatically when I press any button. I use "Player Input Manager" to achieve this....
Read more >
Unity Input System Button Triggers Multiple Times
Issue is a bug within Unity. Solution is to check that player prefab is in scene as the player and it's prefab (only...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found