ScriptableObject reverting to previous state even after scene save, project save.

I have a number of scriptableObjects where I’m setting many parameters to configure levels.

Some of the scriptableObjects are randomly reverting to a previous state, even after multiple scene saves and project saves.

It is driving me crazy because after many hours configuring one, I will open another only to find that it has reverted to a past state. It isn’t affected by the changes made to the others, it really is reverting to a previous state while more recent changes are kept in others.

I have lost a lot of work because of that. I’m at a point where I don’t know if I should change my approach and not use scriptableObjects.

I have created a class to keep saving the project, while using the editor or during play, and placed EditorApplication.ExecuteMenuItem("File/Save Project"); there thinking it would help.

I am thinking it might be because I have duplicated those scriptableObjects from an initial one, and grew from there. If that is the problem, is there a way to fix this for those I have created already? And how should I go about building a scriptableObject from a previous one?

It is also weird because I test closing the scene, restarting play, a lot, and it seems like it is saved. But then, just now that I had Unity closed during the weekend, I open it and found some of them reverted to what I did at the beginning of Friday while others I edited late in that day are intact.

I am using git, I don’t know if that matters.

Thank you

Are you calling EditorUtility.SetDirty() on the ScriptableObject instance itself??

        EditorUtility.SetDirty(filthyDirtyChangedAsset);

This matters a LOT and is GREAT because you can instantly see what got changed.

BUT!!! Huge warning: Unity does not write changes to disk until you press either Save-Scene or Save-Project. (Or also if you leave Unity editor entirely, obviously, as long as you dirtied above)

Is that perhaps part of your problem too?

Thank you for the response @Kurt-Dekker !

I was not calling EditorUtility.SetDirty(). I had read about it but was confused about its use.

I have given it a try and it seems like it is working. Undos are not a major concern, so I think this will solve the issue just fine.

Thanks again!

That’s usually not necessary unless you change the values of your scriptable object by script or you use a faulty custom editor. The default editor should handle undos and serialization just fine. The issues you describe would be quite typical if the changes hasn’t been properly communicated to Unity.

Flush twice and set dirty… it’s a long way to the Asset Database.