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

Question ScriptableObject Databases sometimes losing contents and/or reference after custom editor changes

Discussion in 'Scripting' started by AbandonedCrypt, Jan 11, 2021.

  1. AbandonedCrypt

    AbandonedCrypt

    Joined:
    Apr 13, 2019
    Posts:
    69
    I'm writing a custom editor workflow using multiple SO Databases.

    The Databases, the classes they hold and their fields are all marked Serializable, any write/update to the databases will either set them dirty or perform a SaveAssets().

    Yet sometimes, for example when I am editing code that is solely responsible for displaying data (by iterating over SO-Database contents and displaying certain fields), after reloading, all content disappears from the database. Even content that previously saved properly and persisted beyond serialization and deserialization.

    I don't know what piece of code I could show to demonstrate my issue due to the weird nature of the issue.

    Here you can see my editor displaying a dummy item:



    When entering and exiting play mode, as well as when reloading the project, this item persists and will be displayed.

    Now I change the width of the duration-field.

    Code (CSharp):
    1. //previously
    2. EditorGUILayout.TextField(FormatDurationString(item.Duration), GUILayout.Width(80));
    3.  
    4. //now
    5. EditorGUILayout.TextField(FormatDurationString(item.Duration), GUILayout.Width(50));
    And the content disappears, also the SO is now empty again.

    This does not happen always and what triggers it seems kind of random. Last time it got triggered by me changing the way I format my duration-string.
     
    Last edited: Jan 11, 2021
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,756
    Are you using
    Undo.RecordObject()
    appropriately?
     
  3. AbandonedCrypt

    AbandonedCrypt

    Joined:
    Apr 13, 2019
    Posts:
    69
    I have not used nor known about it up until now, but I'll definitely give it a shot. Thank you.
     
    Kurt-Dekker likes this.