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

Modifying PropertyField child elements

Discussion in 'UI Toolkit' started by Alex-Chouls, Aug 29, 2021.

  1. Alex-Chouls

    Alex-Chouls

    Joined:
    Mar 24, 2009
    Posts:
    2,613
    I'm using this extension method to modify PropertyField GUI child elements that are only generated after binding:

    Code (CSharp):
    1.         public static void OnPopulated(this PropertyField propertyField, Action callback)
    2.         {
    3.             if (propertyField.childCount > 0)
    4.             {
    5.                 callback?.Invoke();
    6.             }
    7.             else
    8.             {
    9.                 propertyField.schedule.Execute(() => OnPopulated(propertyField, callback));
    10.             }
    11.         }
    I've also seen people using OnGeometryChanged event for this, but this seems to work better.

    Either way, it feels pretty hacky.

    Is there a better way to do this?
    Can we get an event for this?

    PropertyFields are a major building block in Editor UI and it seems like they should be easier to work with.
     
  2. JG-Denver

    JG-Denver

    Joined:
    Jan 4, 2013
    Posts:
    77
  3. Alex-Chouls

    Alex-Chouls

    Joined:
    Mar 24, 2009
    Posts:
    2,613
    JG-Denver likes this.