Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Buttons inside ScrollViews are clicked despite scrolling/dragging

Discussion in 'UI Toolkit' started by Midiphony-panda, Apr 15, 2021.

  1. Midiphony-panda

    Midiphony-panda

    Joined:
    Feb 10, 2020
    Posts:
    234
    Hello !

    The issue is (still) noticed with latest UITK package versions (preview 14). It might be fixed/handled in Unity 2021.2 but I'm looking for some info about whether we could expect a fix in preview 15, or some hints to fix the issue. To be short : I'm thinking of disabling SendIMGUIEvents in DefaultEventSystem.cs for UNITY_ANDROID + UNITY_IOS and would like to know the implications of that.

    Here's the main issue (better seen starting from 0:20) :


    When :
    - putting finger down on a button inside a ScrollView
    - moving finger to scroll
    - releasing finger while still on top of the button
    => the Button is clicked

    Expected behaviour would be that the Button would not try to handle the pointer, as the ScrollView should capture the pointer

    (reported in case 1329245)

    There are some nasty things happening with pointer handling/capturing, this is what I noticed when debugging ScrollView.cs and PointerClickable.cs a built Android player :
    • When putting finger down :
      • The mouse(???) PointerDownEvent (pointerId=0) is sent :
        • the mouse pointer (pointerId=0) is set as the scrollingPointer by the ScrollView
        • the Button's PointerClickable captures this mouse pointer
        • the ScrollView receives the PointerCapture event and will register the mouse events callbacks
      • the touch PointerDownEvent (pointerId=1) is sent :
        • ScrollView ignores this pointer, because it is different from the scrollingPointer already set
        • the Button's PointerClickable captures this touch pointer
        • the ScrollView receives the PointerCapture event and will register the touch events callbacks
    • When moving finger :
      • The mouse PointerMoveEvent (pointerId=0) is sent :
        • ScrollView notices that the scrollOffset has changed, and will send a PointerCancelEvent to the target...
        • ... meaning that the Button's PointerClickable releases the mouse pointer
      • the touch PointerMoveEvent (pointerId=1) is sent :
        • ScrollView ignores this pointer, because it is different from the scrollingPointer already set, so it won't send a PointerCancelEvent to the Button's PointerClickable
        • as a result the Button's PointerClickable is still listening to the touch pointer and will invoke a click if the Button can receive a PointerUpEvent
    • When releasing finger (on top of the Button)
      • The mouse PointerUpEvent (pointerId=0) is sent :
        • ScrollView releases the pointer and starts the pointer up animation
      • the touch PointerUpEvent (pointerId=1) is sent :
        • the Button's PointerClickable triggers the click event

    I was scratching my head about a potential fix in the ScrollView until I had a weird idea :

    What if (in our side) we prevented every "mouse" pointer events (sent from DefaultEventSystem.cs at Update with SendIMGUIEvents()) on mobile ?

    From my tests, it looks like it fixes the issue on built mobile players and it still works well in the Device Simulator (we lose the ability to interact from the Game tab but hey, at least we have a working game).
    EDIT : the ClickEvents don't propagate anymore but the buttons and anything that doesn't rely on these events still work
    EDIT 2 : actually, ClickEvents are just extra sensitive with touch events. The ClickDetector cancels the tracking as soon as it receives a PointerStationaryEvent (it comes from the touch in TouchPhase.Stationary which is
    extra sensitive)
    Also if we keep DefaultEventSystem as it is, ClickEvents can be generated for both IMGUIEvents and touch events (meaning 2 ClickEvents generated for one click)



    So it would be cool to have info like :
    • implications of removing SendIMGUIEvents from the DefaultEventSystem, and would it be relevant to fix this issue (in our side, in an embedded UITK runtime package)
    • what did this comment involve in ScrollView.cs : "We need to ignore temporarily mouse callback on mobile because they are sent with with the wrong type"
    • maybe an ETA for package preview 15 and whether we should expect or not a fix for this particular issue
     
    Last edited: Apr 16, 2021
    vakau likes this.
  2. sebastiend-unity

    sebastiend-unity

    Unity Technologies

    Joined:
    Nov 9, 2015
    Posts:
    183
    Hi,

    Great detailed feedback! I am taking it all to our backlog -- can't guarantee that everything will be fixed by next package preview release but we will try to have them in by 21.2.
     
    vakau and Midiphony-panda like this.
  3. Chris-Ender

    Chris-Ender

    Joined:
    May 23, 2015
    Posts:
    12