Mixedrealitytoolkit-unity: Compound Buttons get double-clicked with Hololens

Created on 26 Jul 2018  路  10Comments  路  Source: microsoft/MixedRealityToolkit-Unity

Overview

Having an example scene that has one button (HolographicButton prefab) and an handler attached with:

GetComponent<Button>().OnButtonClicked += _ => Debug.Log("click");

When you press the button with in-Unity Hololens emulation, Hololens remote or with a full Hololens build, you have a double click of the button.

The clicks are not simultaneous and you can prevent the second click if you quickly move your head out of the button.

This also happens in another use case where clicking a button destroys it and another button is behind it or replacing it - both get clicked then.

Expected Behavior

The OnButtonClick is called once.

Actual Behavior

The OnButtonClick is called twice with two different stack traces:

Clicked obj=HolographicButton (UnityEngine.GameObject) event=
UnityEngine.Debug:LogFormat(Object, String, Object[])
ButtonClickHandler:ButtonClickHandler_OnButtonClicked(GameObject) (at Assets/ButtonClickHandler.cs:21)
HoloToolkit.Unity.Buttons.Button:DoButtonPressed(Boolean) (at Assets/HoloToolkit/UX/Scripts/Buttons/Button.cs:310)
馃 HoloToolkit.Unity.Buttons.Button:OnInputDown(InputEventData) (at Assets/HoloToolkit/UX/Scripts/Buttons/Button.cs:139)
HoloToolkit.Unity.InputModule.InputManager:<OnSourceDownEventHandler>m__6(IInputHandler, BaseEventData) (at Assets/HoloToolkit/Input/Scripts/Utilities/Managers/InputManager.cs:454)
UnityEngine.EventSystems.ExecuteEvents:ExecuteHierarchy(GameObject, BaseEventData, EventFunction`1)
HoloToolkit.Unity.InputModule.InputManager:HandleEvent(BaseEventData, EventFunction`1) (at Assets/HoloToolkit/Input/Scripts/Utilities/Managers/InputManager.cs:296)
馃 HoloToolkit.Unity.InputModule.InputManager:RaiseSourceDown(IInputSource, UInt32, InteractionSourcePressInfo, Object[]) (at Assets/HoloToolkit/Input/Scripts/Utilities/Managers/InputManager.cs:463)
HoloToolkit.Unity.InputModule.CustomInputSource:SendControllerStateEvents(Single) (at Assets/HoloToolkit/Input/Scripts/InputSources/CustomInputSource.cs:454)
HoloToolkit.Unity.InputModule.CustomInputSource:UpdateControllerState(DebugInteractionSourceState) (at Assets/HoloToolkit/Input/Scripts/InputSources/CustomInputSource.cs:441)
HoloToolkit.Unity.InputModule.CustomInputSource:UpdateControllerData() (at Assets/HoloToolkit/Input/Scripts/InputSources/CustomInputSource.cs:365)
HoloToolkit.Unity.InputModule.CustomInputSource:Update() (at Assets/HoloToolkit/Input/Scripts/InputSources/CustomInputSource.cs:302)
Clicked obj=HolographicButton (UnityEngine.GameObject) event=
UnityEngine.Debug:LogFormat(Object, String, Object[])
ButtonClickHandler:ButtonClickHandler_OnButtonClicked(GameObject) (at Assets/ButtonClickHandler.cs:21)
HoloToolkit.Unity.Buttons.Button:DoButtonPressed(Boolean) (at Assets/HoloToolkit/UX/Scripts/Buttons/Button.cs:310)
馃 HoloToolkit.Unity.Buttons.Button:OnInputClicked(InputClickedEventData) (at Assets/HoloToolkit/UX/Scripts/Buttons/Button.cs:173)
HoloToolkit.Unity.InputModule.InputManager:<OnInputClickedEventHandler>m__4(IInputClickHandler, BaseEventData) (at Assets/HoloToolkit/Input/Scripts/Utilities/Managers/InputManager.cs:402)
UnityEngine.EventSystems.ExecuteEvents:ExecuteHierarchy(GameObject, BaseEventData, EventFunction`1)
HoloToolkit.Unity.InputModule.InputManager:HandleEvent(BaseEventData, EventFunction`1) (at Assets/HoloToolkit/Input/Scripts/Utilities/Managers/InputManager.cs:296)
馃 HoloToolkit.Unity.InputModule.InputManager:RaiseInputClicked(IInputSource, UInt32, InteractionSourcePressInfo, Int32, Object[]) (at Assets/HoloToolkit/Input/Scripts/Utilities/Managers/InputManager.cs:411)
HoloToolkit.Unity.InputModule.CustomInputSource:SendControllerStateEvents(Single) (at Assets/HoloToolkit/Input/Scripts/InputSources/CustomInputSource.cs:479)
HoloToolkit.Unity.InputModule.CustomInputSource:UpdateControllerState(DebugInteractionSourceState) (at Assets/HoloToolkit/Input/Scripts/InputSources/CustomInputSource.cs:441)
HoloToolkit.Unity.InputModule.CustomInputSource:UpdateControllerData() (at Assets/HoloToolkit/Input/Scripts/InputSources/CustomInputSource.cs:365)
HoloToolkit.Unity.InputModule.CustomInputSource:Update() (at Assets/HoloToolkit/Input/Scripts/InputSources/CustomInputSource.cs:302)

Steps to reproduce

There is a test scene at
https://github.com/chanibal/bug-MixedRealityToolkit-Unity/tree/button-bug-test-case

Unity Editor Version

2018.2.0f2

Mixed Reality Toolkit Release Version

Checked with:

  • Current master (84493c97)
  • Current Dev_Working_Branch (10d94660)
  • Current release

All 10 comments

It could be because you're registering to the button click directly instead of the event passed through the event system.

You're also not marking the event as used, and checking if it's been used which would prevent it from getting raised a second time. That might help as well.

This bug should be fixed in the June Dev branch, but hasn't made its way into a release yet. Please pull that code and let me know if you still have a repro.

The corresponding change set can be found at #2367.

(The button click event being registered for here is a pass through of the input system event via Button.cs, so registering for it is the intended use. The underlying event response does mark the event as used.)

@StephenHodgson: I use the OnButtonClicked event the same as MRTK uses it, checkout for example the DialogButton class.
And how should I mark the event as used? It's not forwarded to the OnButtonClicked, and by the time the event handler gets called Event.current is null.
Not to mention, that these are two different events.

Ah, @keveleigh is correct. This is a bug that's been fixed and should find its way into the next release.

Tried to reproduce with june18_dev branch and failed - so this has been fixed there. This is clearly a duplicate, sorry, searched before posting, but missed that one.

OK, but how should I use the buttons at this point? Just use IInputClickHandler?

OK, but how should I use the buttons at this point? Just use IInputClickHandler?

That is correct.

OK, but how should I use the buttons at this point?

If you want to use the HolographicButton prefab, your original registration code looks right to me. Is it not working?

Thank you for your help, @StephenHodgson and @keveleigh, closing issue.

@keveleigh - the issue was with HolographicButton at master branch, which I use at this point - will use IInputClickHandler until the fix you mentioned gets merged.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

provencher picture provencher  路  3Comments

brean picture brean  路  3Comments

markgrossnickle picture markgrossnickle  路  3Comments

matatabi-ux picture matatabi-ux  路  3Comments

dustin2711 picture dustin2711  路  3Comments