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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

RegisterCallback<ClickEvent> triggers twice on Linux only

Discussion in 'UI Toolkit' started by leondeandrade313, May 18, 2021.

  1. leondeandrade313

    leondeandrade313

    Joined:
    Apr 7, 2021
    Posts:
    5
    Hi,

    I noticed when using

    ```
    element.RegisterCallback<ClickedEvent>(evt => Debug.Log("Clicked Event"));
    ```
    or

    ```
    element.RegisterCallback<MouseDownEvent>(evt => Debug.Log("Mouse Down Event"));
    ```

    It always triggers twice and ONLY on Linux. No Issue on Windows as far as I can tell.

    What works is using a manipulator though:


    ```
    element.AddManipulator(new Clickable(evt => Debug.Log("Clicked Manipulator")));
    ```
    Works like a charm, only triggers once.


    So there are two questions:

    1. Is this a known bug? Is there some fix for it or workaround other than using manipulators

    2. Is there a Manipulator for the MouseDownEvent as a workaround for now?
     
    a4ism likes this.
  2. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    735
    Hi!

    That is very strange. This is not a known bug as far as I know, would you mind submitting a bug through Help > Report a bug so our internal QA can reproduce it?

    Thank you.
     
  3. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    735
    About possible workarounds, I wonder about your current set-up. Which version(s) are you using? What is your setup for event system / input ?
     
  4. leondeandrade313

    leondeandrade313

    Joined:
    Apr 7, 2021
    Posts:
    5
    Hi,

    my current setup is 2020.3.2f1 and I use the preview 14 of UI and Builder.

    As a workaround I tried to subclass https://docs.unity3d.com/ScriptReference/UIElements.Clickable.html and override ProcessDownEvent and in fact that executed twice as well.
    So the issue seems to be in the deeper Codebase I guess.

    I will report a Bug later!

    Btw. I reproduced this on a second machine as well.


    And my workaround is now:

    ```
    if (Mathf.Abs(mouseDownEvent.timestamp - lastClick) < 100)
    return;

    lastClick = mouseDownEvent.timestamp;
    ```

    in my Click Handler to ignore the second click.

    Let me know if you know anything better than that.
     
    Last edited: May 18, 2021
    willtospawn likes this.
  5. zamazan4ik_unity

    zamazan4ik_unity

    Joined:
    Feb 16, 2021
    Posts:
    1
    I've reproduced the same behavior on my Linux machine (Fedora 34, KDE, Wayland, latest stable Unity version and the latest UI toolkit).

    Any updates?
     
  6. AWildYvyHasAppeared

    AWildYvyHasAppeared

    Unity Technologies

    Joined:
    Jan 19, 2021
    Posts:
    3
    Hi there!

    The issue has been logged and is trackable here.
     
  7. niel-archer

    niel-archer

    Joined:
    Nov 29, 2016
    Posts:
    17
    Experiencing this on Manjaro with Unity 2021.2.0b14
     
    Last edited: Oct 5, 2021
  8. mNKA

    mNKA

    Joined:
    Aug 19, 2021
    Posts:
    14
    sadly this bug is still around/reappeared, at least for Ubuntu 22.04 and Unity2022.2.3f1

    edit: not only for Click Events but also for every other Pointer Event, like PointerMoveEvent, PointerDownEvent, etc.
    the only differences i can see are timestamp where the 2nd event is fired one tick later, and position where is a difference below 0.5 on x and y.
     
    Last edited: Feb 13, 2023