Search Unity

Pointer up is not being generated

Discussion in 'UI Toolkit' started by unity_B9Hl2lkooCHApw, Sep 12, 2021.

  1. unity_B9Hl2lkooCHApw

    unity_B9Hl2lkooCHApw

    Joined:
    Apr 19, 2019
    Posts:
    26
    Hello UI Toolkit experts,

    at the moment I am trying to create some sort of radial menu for my game. It will work like this:

    The user holds the mouse button, the menu appears. He hovers over a menu option - it is being selected by evaluating the mouse position relative to the center of the menu. When the user lets go of the mouse button, the selected option is being confirmed and the menu is hidden again.

    The steps:
    1) The game detects that the user has long-pressed somewhere within a behavior.
    2) The behavior gets disabled, the UI, just 5 plain visual elements at the moment, is made visible.
    3) While the user still holds down the mouse button, the mouse is captured by the radial menu.
    4) The mouse-move-events are generated and are being captured properly by the radial menu.
    5) When releasing the mouse, no mouse-up-event is being received. I have to press the button again and release it to make it count. The pointer up event is only being generated when there is a pointer down event before.

    downup1.PNG
    downup2.jpg

    Is this a bug? How can I make the event system aware of the fact that there has been a pointer down event sometime before?

    BR,

    Andrej

    PS: Maybe some code might help:
    This is called when the behavior detects the long press:
    Code (CSharp):
    1. public void ShowContextMenu(int mouseButton)
    2.     {
    3.         radialContextMenu.Show(defaultInputHandler.activeCamera, mouseButton);
    4.         enabled = false;
    5.     }
    This is how the mouse is captured by the UI:
    Code (CSharp):
    1. public void Show(ACam activeCamera, int mouseButton)
    2.     {
    3.         this.mouseButton = mouseButton;
    4.  
    5.         center.CaptureMouse();
    6.         center.style.display = DisplayStyle.Flex;
    7.     }
    And this is the method that is called when the mouse-up-event is received:
    Code (CSharp):
    1. private void ConfirmSelection(MouseUpEvent e)
    2.     {
    3.         if(e.button != mouseButton) return;
    4.         center.ReleaseMouse();
    5.         center.style.display = DisplayStyle.None;
    6.         inputStateMachine.OnContextMenuOptionChosen();
    7.         Debug.Log("option chosen!");
    8.     }
    This is where my non-ui input handling is reactivated:
    Code (CSharp):
    1. public void OnContextMenuOptionChosen()
    2.     {
    3.         enabled = true;
    4.         currentState = defaultInputHandler;
    5.     }  
     
  2. uBenoitA

    uBenoitA

    Unity Technologies

    Joined:
    Apr 15, 2020
    Posts:
    220
    Hi. Is this a runtime menu, or a menu from an EditorWindow? If runtime, what other objects are present in your scene, apart from the UIDocument (an EventSystem for example)? Maybe I could help if I had a look at a zip of your project. I've seen something that looks like what you're describing recently, but only in specific circumstances, that's why I'm asking for more context.
     
  3. unity_B9Hl2lkooCHApw

    unity_B9Hl2lkooCHApw

    Joined:
    Apr 19, 2019
    Posts:
    26
    Hello Benoit,
    thank you for your response. This happens with my runtime radial menu.
    I submitted my project as a bug (Case 1366568).
    I'm looking forward to a fix :)

    BR,

    Andrej

    PS: I tried to reproduce the bug in a fresh project but it worked as intended. If you also need that 'minimal' project for comparison, I can share that with you too.
     
  4. unity_B9Hl2lkooCHApw

    unity_B9Hl2lkooCHApw

    Joined:
    Apr 19, 2019
    Posts:
    26
    Hello,
    it has been a while. Any news on this bug?

    BR,

    Andrej
     
  5. doctorseus

    doctorseus

    Joined:
    Feb 27, 2013
    Posts:
    12
    Hi, I have a similar use-case as OP. As uBenoitA hinted at, it happens if you have an EventSystem present and enabled while you are using UI Toolkit. I have to do that as I need to use features not available to UI Toolkit yet for some UI elements.
    uBenoitA posted a workaround here: https://forum.unity.com/threads/uit...th-the-new-input-system.1091461/#post-7030699 which works for me:
    EventSystem.SetUITookitEventSystemOverride(null, false, false);


    I am working with Unity 2021.1.21f1 and only enabled the old Input System.