- Home /
Set Dirty and Save Scene
Hi. I had wrote a custom inspector for some class Container
. This class contains an array (public) of serializable class ContainerItem
. From my custom inspector I vary this array, and if some changes to this array applied I use EditorUtility.SetDirty(container);
This works just fine, items added through inspector are there on playmode and after. But. But if I add item and close Unity changes not saved. And if I add item and click Ctrl+S (although unity not saying there were changes on scene), then item is saved after reset.
I'm not too experienced with custom inspectors and serialization and whatewer. Why unity not saying there are changes at scene to save? How to force editor to save scene or to track changes? I just need it at least to remind me to save changes.
Are you using Scriptable Objects ? If so try using AssetDatabase.SaveAssets();
No, in this case my Container is $$anonymous$$onoBehaviour and ContainerItem is serializable class with no inheritance
Extend the ContainerItem with ScriptableObject and try the same.
Thanks. I use ScriptableObjects for many things in my projects. Just thought that'll be too cumbersome in this case.
I form the full answer as an Answer below :)
Answer by Deadcow_ · Jul 03, 2015 at 08:11 AM
Thanks. I use ScriptableObjects for many things in my projects. Just thought that'll be too cumbersome in this case.
So, I decided to use SerializedObjects instead
var serialized = new SerializedObject(container);
var items = serialized.FindProperty("Items");
items.arraySize++;
serialized.ApplyModifiedProperties();
container.Items[container.Items.Length - 1] = containerItem;
Now I get "Save Changes?" window on shutdown. But then I though, meh, what the heck, and ended up with a single line:
EditorApplication.SaveScene();
Your answer
![](https://koobas.hobune.stream/wayback/20220613201654im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
If I make changes to a prefab in the Project tab, do I have to save the scene, too? 1 Answer
Will Restoring my computer restore my scene? 0 Answers
Byte array of serialized data in MonoBehavior - changes not written to disk 1 Answer
Scene got cleared, but the file size is still 108kb 1 Answer
Get dirty state from a scene 3 Answers