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

Set callbacks in the Editor

Discussion in 'UI Toolkit' started by bleppie2, Mar 18, 2020.

  1. bleppie2

    bleppie2

    Joined:
    Mar 25, 2015
    Posts:
    5
    One of the lovely things about Unity.UI is the ability to set callbacks in the Editor (see below for an example). Is/will there be any way to do this In UI-Toolkit? As far as I can tell, callbacks can be set only in C# code.

    So something like this:

    ScreenCap 2020-03-18 at 1.55.09 PM.png

    Becomes something like this:

    root.Q<Button>("My Button").RegisterCallback<MouseUpEvent>
    (evt => transform.root.Find("Man").gameObject.SetActive(false));
     
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,203
    uGUI achieved the above workflow via Reflection which is not ideal for performance nor usability (as it just lists all valid functions without regard to which functions make sense to be called from the UI). It also made it difficult to debug in complex situations as it was unclear who calls who and why.

    We do want to make binding to functionality easier and code-less in UI Toolkit (formally UIElements) but we don't want to approach the feature the same way. As such, it will takes some time to add to UI Builder. It may leverage Visual Scripting or might involve code generation (like you proposed above). But too early to tell.
     
  3. bleppie2

    bleppie2

    Joined:
    Mar 25, 2015
    Posts:
    5
    Thanks for the reply!