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

Resolved UI Toolkit PropertyDrawer Serializing Problem.

Discussion in 'UI Toolkit' started by xOrfe, Apr 23, 2023.

  1. xOrfe

    xOrfe

    Joined:
    Apr 21, 2013
    Posts:
    31
    I created a custom PropertyDrawer to create an editor tool, but I need to make changes in the scene for the serialized data to be saved. After making changes in the custom property without making any changes in the scene, when I close(ofc after saving scene) and reopen the editor, I see that the changes are not saved. However, when I make any changes in the scene (such as changing position), it is saved correctly. What can I do about this problem?
     
    Last edited: Apr 24, 2023
  2. oscarAbraham

    oscarAbraham

    Joined:
    Jan 7, 2013
    Posts:
    431
    Changes to serialized data aren't saved if the modified objects aren't set dirty. There's an utility method for that, but it's usually better to make the changes through a SerializedProperty, as it handles a lot of other things, like prefab overrides. Ideally, you'd use custom BindableElements inside your property drawer that you then bind to different properties; that way, Unity handles the serialization stuff.

    Can you share an example of something that is not saved through your custom property drawer? It'd be easier to diagnose your problem that way.
     
    xOrfe likes this.
  3. xOrfe

    xOrfe

    Joined:
    Apr 21, 2013
    Posts:
    31
    Thank you so much for detailed and helpful answer @oscarAbraham. I am developing color wheel tool and i cant directly bind something in this case. But the set dirty feature you mentioned about solves my problem. Thank you so much again, have a nice day<3
     
    Last edited: Apr 30, 2023
    oscarAbraham likes this.