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

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.

//previously
EditorGUILayout.TextField(FormatDurationString(item.Duration), GUILayout.Width(80));

//now
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.

Are you using Undo.RecordObject() appropriately?

I have not used nor known about it up until now, but I’ll definitely give it a shot. Thank you.

1 Like