New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Button.OnButtonClicked is triggered twice on clicks #1879
Comments
Similar with the HolographicButton prefab in dev working branch. Unity 2017.2.1p4 https://forums.hololens.com/discussion/6999/ui-button-on-click-event-firing-twice#latest |
I'm currently solving this by simply debouncing the invocation of |
|
|
You'll have to show me how you've got it setup in the inspector and in code. |
Unfortunately i just left my windows machine at work, but i will try to flesh out my description a bit. ReproductionThis seems to be not reproducible in the Unity Editor, it only fails on the HoloLens itself.
using UnityEngine;
using MixedRealityToolkit.UX.Buttons;
class Test : MonoBehaviour {
int frame = 0;
private void Start() {
Button button = this.GetComponent<Button>();
button.OnButtonClicked += (target) => {
Debug.Log(frame);
Debug.Log(System.Environment.StackTrace);
}
}
private void Update() {
frame++;
}
} Run. IssueThe Issue seems to be in the handling of input events in public void OnInputDown(InputEventData eventData)
{
if (enabled)
{
if(ButtonPressFilter == InteractionSourcePressInfo.None || ButtonPressFilter == eventData.PressType)
{
DoButtonPressed(); // This calls button pressed on
// Set state to Pressed
ButtonStateEnum newState = ButtonStateEnum.Pressed;
this.OnStateChange(newState);
}
}
}
public void OnInputClicked(InputClickedEventData eventData)
{
if (enabled)
{
if (ButtonPressFilter == InteractionSourcePressInfo.None || ButtonPressFilter == eventData.PressType)
{
DoButtonPressed(true);
}
}
}
// As you can see both events result in DuButtonPressed() being called.
// This then triggers OnButtonClicked
protected void DoButtonPressed(bool bRelease = false)
{
ButtonStateEnum newState = ButtonStateEnum.Pressed;
this.OnStateChange(newState);
if (OnButtonPressed != null)
{
OnButtonPressed(gameObject);
}
if(OnButtonClicked != null)
{
OnButtonClicked(gameObject);
}
if (bRelease)
{
StartCoroutine(DelayedRelease(0.2f));
}
} |
here's a basic project where i am trying to use additional button in AppBar http://bradensmith.com/vrar/_testHoloButtons.7z Click on button 'test' and it prints debug line twice |
Not a fan of just downloading binaries. Could you make a public repo here on Github? |
|
I created a test scene for you in here: Disclaimer: i could not base the test of the current dev branch, because of some exception, so i used d46126f |
I have the same or a similar problem it seems. Added eventData.Use() ... still both OnInputDown and OnInputClicked are called. Seems in my case at least one event is from GestureRecognizer_Tapped, the other the other both coming from InteractionInputSource In the editor/player the call stack is:
2)
While debugging on HoloLens, the callstack is
2)
|
DoButtonPressed is the problem here. It contains both, OnButtonPressed and OnButtonClicked, while it's been called from both, OnInputDown and OnInputClicked. |
Maybe this problem is related with #2040 |
I have a rework in progress, so I'll be sure to double check #2040 as well. |
The PopupMenu issue ended up needing a different fix, since it uses a different button class than this one. I've noted that, so we can clean up the various overlapping UX components. |
Just opened #2367 to remove the duplicate events firing. |
Overview
OnButtonClicked
is triggered twice on input clicks. Once from the InputClickedEvent and once from InputDown.This happens spread over some frames and thus causes unintended side effects with dialogs and button actions that spawn gameObjects infront of the user. For example the first
InpudClicked
event will open a Dialog and the second will imediately dismiss it.Expected Behavior
OnInputClicked
is only fired onceActual Behavior
OnInputClicked
is fired twiceSteps to reproduce
OnButtonClicked
Unity Editor Version
2017.3.1f1
Mixed Reality Toolkit Release Version
dev branch @ d46126f
Edit: Added commit hash
The text was updated successfully, but these errors were encountered: