Search Unity

Existing UI control

Discussion in 'UI Toolkit' started by andx3roo, Apr 1, 2020.

  1. andx3roo

    andx3roo

    Joined:
    Mar 13, 2020
    Posts:
    3
    Is there a way to get the existing elements of Unity Editor UI and subscribe functions to their events? For instance, take the step button in the unity editor. Is there a generic (not just for this button) way to get and possibly reorder its callback?
     
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    Do you mean this button?
    upload_2020-4-1_17-27-51.png

    For that specific button, there is no general way to know if that button was clicked from the UI alone. There are specific callbacks in the Editor to help you hook into the Playmode state changes.

    In general through, because the UI in the editor can be implemented with IMGUI or UI Toolkit (formally UIElements), there is no one "simple" way to know if any button is clicked (or any other event). Even just in UI Toolkit, some elements might be easy to find via query by name, some not so easy (they have no name). Furthermore, again in UI Toolkit, events can be captured by other elements (either parents or children of the element you're interested in), so you might not get the event you're looking for by just registering a callback on your target element.

    More info on what specifically you're trying to do would help in suggesting some approaches to the problem. As in, why do you need such a generic UI-only way of knowing when the user does something in the Editor?
     
  3. andx3roo

    andx3roo

    Joined:
    Mar 13, 2020
    Posts:
    3
    I need to pause and step physics simulations in a separate thread (native) in my plugin within editor (so I also don't want to be replacing the bar entirely as I've seen some do). I can't seem to find the "hooks" for these.

    I've also had other various issues with lack of control on Unity's UI so I wanted to know a generic way as I thought was possible UI toolkit but not imgui. Are there plans to replace all non customizable Unity imgui with UI toolkit?

    I guess you are right though. If something else captures the UI event first I'm out of luck. And there's no way to place a guaranteed callback on a UI element (something else capturing it won't stop it from being called)?