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

Stop clicks on reaching gameobjects

Discussion in 'UI Toolkit' started by unitydungeonmas, Sep 24, 2020.

  1. unitydungeonmas

    unitydungeonmas

    Joined:
    Sep 6, 2020
    Posts:
    37
    I register the click event to stop propagation but it still reaches gameobjects behind the uidocument:

    Code (CSharp):
    1. UIDocument u = gameObject.GetComponent<UIDocument>();
    2. u.rootVisualElement.RegisterCallback<ClickEvent>(e => e.StopImmediatePropagation());
    Code (CSharp):
    1. UIDocument u = gameObject.GetComponent<UIDocument>();
    2. u.rootVisualElement.RegisterCallback<ClickEvent>(e => e.StopPropagation());
     
  2. manuelgoellnitz

    manuelgoellnitz

    Joined:
    Feb 15, 2017
    Posts:
    365
    My guess is, it stops only the click within the UIToolkit System, but the klick event in the 3D world and the old system is still there.
    I think since it has it's own EventHandler, a click creates one clickevent for each of them which have no effect on each other.
     
  3. uMathieu

    uMathieu

    Unity Technologies

    Joined:
    Jun 6, 2017
    Posts:
    384
    That's exactly what happens. This is already in our backlog and we'll have a built-in solution in the future.

    In the meantime, something that could work:

    Add RegisterCallbacks on the root element, for both the TrickleDown and bubble up phase and if you don't get the second one, that means the click was handled. You can then set a global flag to query from the scene later.
     
    Karlbovsky and unitydungeonmas like this.
  4. unitydungeonmas

    unitydungeonmas

    Joined:
    Sep 6, 2020
    Posts:
    37