- Home /
Why is ScriptableObject asset not saving to disk?
I have these nested classes that I want to save:
[CreateAssetMenu(order = 0)]
[System.Serializable]
public class Quest : ScriptableObject
{
public string name;
public string description;
[SerializeField] List<QuestSection> sections;
}
[System.Serializable]
public class QuestSection
{
public string name;
public string description;
[SerializeField] List<QuestObjective> objectives;
}
[System.Serializable]
public class QuestObjective
{
public string name;
public string description;
}
I made an editor window to edit it after creation and save in disable or when a button in the editor is pressed:
public void Save()
{
if(AssetDatabase.Contains(currentQuest)) //The quest being edited
{
AssetDatabase.SetDirty(currentQuest);
AssetDatabase.Refresh();
AssetDatabase.SaveAssets();
}
}
The name and description of the Quest class are still there after unity restart. The list empties out.
I've set the classes and variables to serialize, I've used various combinations and sequences of SetDirty(), Refresh(), and SaveAssets() but none have worked. Each time I close the editor and open again, the asset is still there, but has an empty list (which I can see in the inspector before even opening my custom editor window so this is not the problem). While the editor is open everything is fine, so it seems to be a save-to-disk problem. I've gone through many forum threads which only give the above answers. Any directions would be appreciated.
Edit: Tried making this work using the Serialized object functions. No luck
Answer by hectorux · Nov 10, 2018 at 12:20 AM
Is an error with custom editor, if you copy the component values after setting up your things in the inspector, and then paste them, it will work (2018.3.4b)
Is an error with custom editor
You mean a Unity bug?
I tried copying and pasting values but not sure what you mean by that. I set all my values in the inspector window as opposed to custom editor and still didn't save to disk.
Answer by Matt1000 · Nov 10, 2018 at 10:45 PM
Have you actually tried applying those to the ScriptableObject?
currentQuest.SetDirty();
Does that work in a custom editor window? CurrentQuest is just an instance of the Quest class referring to the ScriptableObject being edited. I did try the Apply$$anonymous$$odifiedProperties() etc which didn't do anything. I'll check as soon as I get home.
Edit: Didn't work sadly. Also gives deprecated warning and says to use AssetDatabase.SetDirty()