Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Updating Inspector using non serializable properties

Discussion in 'UI Toolkit' started by ratuspro, Jun 12, 2022.

  1. ratuspro

    ratuspro

    Joined:
    Apr 5, 2015
    Posts:
    17
    Hello,

    I'm currently using UI Toolkit to create a custom inspector for a class with an internal state that is updated several times.
    For instance, I'm currently rendering in the inspector a list that is not serializable (accessible through C# properties) that changes quite often. I'm accessing this property directly using
    Code (CSharp):
    1. ((MyClass)serializedObject.targetObject).myproperty
    However, I would like to be able to bind something to track when the property changes towards updating the inspector accordingly. From my understanding, this is only possible for serializable properties. I would like to know if it is possible to have some binding/callback when non-serializable properties change.

    Another approach would be to force the inspector to be rendered again every X seconds. As it stands, this seems to be the only option since I do not see a way to register callbacks for c# property changes. Is there something similar to Update on MonoBehaviour but for the Editor while using CreateInspectorGUI?

    Thanks in advance
     
  2. uMathieu

    uMathieu

    Unity Technologies

    Joined:
    Jun 6, 2017
    Posts:
    396
    Data bindings are only supported for SerializedProperties at the moment. For plain c# properties, you can do polling via the scheduler:

    Code (CSharp):
    1. myElement.schedule.Execute(() => PollMyNonSerializedListValue()).Every(100);
    PollMyNonSerializedListValue will be called every 100ms as long as myElement is part of the window
     
    ratuspro likes this.
  3. ratuspro

    ratuspro

    Joined:
    Apr 5, 2015
    Posts:
    17