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

Question Managing input priority between UITolkit and Unity GUI

Discussion in 'UI Toolkit' started by sfallier_scopely, Apr 5, 2023.

  1. sfallier_scopely

    sfallier_scopely

    Joined:
    Aug 24, 2020
    Posts:
    7
    I'm experimenting with UI Toolkit and it would like to make use of it in existing project that has a big complicated mess of Unity GUI already implemented. I'm playing around with a test project to see how the two interact when a Canvas and UIDocument are both active at the same time - and the results are not very promising.

    The behavior I'm seeing is that the Toolkit stuff renders above the UGUI stuff, but all input (mouse clicks) are routed to UGUI, and none of the toolkit UI is interactable. If disable the object with the Canvas, the toolkit UI becomes interactable.

    The docs (and various forum posts) claim it's possible to use both of the systems at the same time. There's also documentation that Sort Order on the canvas or UI Document can be used to control the render order (which I would hope also controls input priority), but it's had no affect for me.

    I'm using 2021.3.18f1.

    Am I totally missing something? Is there stuff in the EventSystem I need to muck with to get this to behave in a consistent way (ie, input handling order matches rendering order)?
     
  2. sfallier_scopely

    sfallier_scopely

    Joined:
    Aug 24, 2020
    Posts:
    7
    In case anyone else is battling with this - I found that my headaches were due to toggling the GameObject that holds the UIDocument on and off to control its presence, which definitely seems like a bug. Using gameObject.SetActive() appears to break future input handling. Setting rootVisualElement.style.visibility instead got things working consistently.