x


Why doesn't my ScriptableObject save using a custom EditorWindow?

Solution

Call EditorUtility.SetDirty(yourObject); on any changes made to it.


I have a problem where a ScriptableObject doesn't save its members properly when edited through a custom EditorWindow. It saves properly when edited through the inspector. I can see through the inspector that the ScriptableObject is affected properly by the EditorWindow.

Am I required to explicitly call some SaveAsset() function on the object when editing it through the EditorWindow? Either that, or it might be some bug in Unity. In the former case, does anyone know how I can save the ScriptableObject? In the latter case, does anyone know of a workaround?

Further, the ScriptableObject contains two ints for width and height, and a one-dimensional array of a custom enum type (basically a flattened 2d array). Both the ScriptableObject and the the custom enum type uses System.Serializable attribute on the class and enum type. All fields are public. No properties are being used. The ScriptableObject also exists in the project, so it is not a transient object.


Currently I am trying to force-save the asset through AssetDatabase.SaveAssets. This approach doesn't seem natural as I don't want to necessarily save all assets, only the one I am editing.

However, as I found out after some trial and error AssetDatabase.SaveAssets doesn't actually save the asset as expected.

more ▼

asked Feb 15 '10 at 10:01 AM

Statement gravatar image

Statement ♦♦
20.1k 35 70 175

(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

You need to call EditorUtility.SetDirty() on your scriptable object.

more ▼

answered Feb 15 '10 at 11:33 AM

Lucas Meijer 1 gravatar image

Lucas Meijer 1 ♦♦
8k 19 43 85

That did the trick! (Apparently ScriptableObject.SetDirty also works although it is obsolete.) EditorUtility.SetDirty it is!

Feb 15 '10 at 12:24 PM Statement ♦♦
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1675
x467
x419
x180
x66

asked: Feb 15 '10 at 10:01 AM

Seen: 3863 times

Last Updated: Feb 15 '10 at 12:26 PM