Search Unity

  1. Get the latest news, tutorials and offers directly to your inbox with our newsletters. Sign up now.
    Dismiss Notice

Ways of modifying "auto-populated" PropertyField after CreateInspectorGUI()

Discussion in 'UI Toolkit' started by Buretto, Mar 5, 2020.

  1. Buretto


    Mar 23, 2015
    For a custom inspector, I'm trying to figure out the best/simplest way to modify the elements right after
    . The reason(s) for this is that
    controls the bindings of the property fields I have set in uxml file. So for example, it is convenient that I can assign the
    of a property field to a serializeable class or struct, as the binding system will automatically populate it with the contained values. But if I wanted one of the contained value's enabled/disabled state to be controlled by a toggle/bool value, I can't do this in
    as the property fields haven't been assigned yet (AFAICT the PropertyFields are created when it returns). It would be convenient if I could modify it by overriding a method such as
    , or something like that. Is there a proper way to do that?

    Right now I am adding all contained values as PropertyFields by hand within
    , so I can set the state as they are added to the root; but this is not ideal as I may have, say, 15 fields in the class/struct and only need set the state of 1.
  2. uDamian


    Unity Technologies

    Dec 11, 2017
    You can use the
    on your custom Editor's root element (the element returned from
    ). That will always be called the first time the elements are layed out (and all following times when their size changes at all). I would recommend immediately unregistering from GeometryChangeEvent once you get it to avoid performance problems down the road. But at this point, all the UI should be created and if it has to be re-created, you can be sure this event will trigger again so you can redo your own custom links between elements.
    Buretto likes this.