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.
@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.