Custom Editor Window Not Saving Scriptable Object
Hi there,
I've spent hours trying to figure out why this isn't working (I've followed everything I've seen on the internet as well). I am creating a conversation editor which represents each message, choice, etc. as a node.
After hitting save I can switch between different conversation asset files no problem; It saves the changes to disk. However, after play testing all of my changes are gone (as in, I press play, the game loads the asset, then wipes it). Here's the code I use to load the asset:
ConversationEditor editor = EditorWindow.GetWindow (); editor.conversation = (Conversation)Selection.activeObject; editor.activeObject = Selection.activeObject; editor.saveLocation = AssetDatabase.GetAssetPath (Selection.activeInstanceID); Undo.RecordObject (editor.conversation, "Edit Conversation");
Here's the code I use to save the asset:
AssetDatabase.Refresh (); EditorUtility.SetDirty (_conversation); AssetDatabase.SaveAssets ();
The conversation class extends Scriptable Object. Please help. I'm not sure what to do anymore.
Answer by Walpeup · May 01, 2016 at 03:51 AM
@FutureProg, I'm not sure if this will solve your problem, but your question solved mine! I was facing the same issue and it was because I wasn't using EditorUtility.SetDirty. I used your method, but had to re-arrange the order of the calls, the following worked for me:
EditorUtility.SetDirty(assetObject);
AssetDatabase.SaveAssets ();
AssetDatabase.Refresh ();
As near as I can tell, the Refresh has to occur at the end to get the editor to re-load the changes that the AssetDatabase just stored.
Happy to help you out, but sorry, it doesn't work for me.
Sorry about that, if you want to check out my entire project you might be able to find something that can help. It's on GitHub at https://github.com/TwoTacos/Voxxy/tree/develop , the ScriptableObject is VoxImporter and the saving starts at line 241.
I'm saving my asset the exact same way that you are. Where is it in the code that you create the VoxImporter asset?
Your answer
Follow this Question
Related Questions
Regarding ScriptableObjects, Inheritance and custom editors 0 Answers
automatically create gameobjects from images in a folder 0 Answers
How to save custom editor data? 0 Answers
Serialize child ScriptableObject asset values in parent ScriptableObject asset. 0 Answers
How to use RenderStaticPreview OR get project viewer thumbnails for ScriptableObject assets? 2 Answers