- Home /
Save EditorWindow to disk
Hi,
Is there a way to save an editor window using AssetDatabase.CreateAsset() ?
What I have is a class that inherits EditorWindow, and it include multiple ScriptableObjects as its members. I have also set the hideFlags to HideAndDontSave in the OnEnable() method to prevent the window losing its data during serialization.
Now I want to save those ScriptableObjects from that editorWindow class to disk so I can load them later in the editor window.
Is this possible?
if not AssetDatabase.CreateAsset(), Even if I could serialize those objects to a file using any serialization method, that would be great.
Thank you.
Answer by Bunny83 · Nov 18, 2013 at 01:44 PM
ScriptableObjects have to be saved on their own. I'm not sure if you can save an editorwindow with CreateAsset, i've never tried this, but it might work since EditorWindows are also ScriptableObjects. I wrote an answer (+ a quite long comment) on this question a few hours ago.
edit
It seems that it's not possible to save and retrive an EditorWindow via Unitys serialization system. See my comment below.
Thanks. I'll have a look at the link. I know that it may have something to do with the hideflag, while we tell unity to not take care of the saving, at the same time I'm trying to save it and it checks for the flag.
I just tested it myself and i'm pretty sure that it doesn't work. That's because the AssetDatabase is the runtime asset database. So erializing editorclasses kind of works, however if the objects is destroyed (i closed the window) the asset file becomes corrupted since the class it represents doesn't exists in the runtime.
The Unity editor of course has the functionality to save such scriptable objects only for the editor (see ProjectSettings and the actual window layout files) however it seems that they don't gave us access to those functions.
So i would say no, it's not possible, but that's my guess at the moment.
btw you actually have to allow saving before you use CreateAsset or you get an assert. The hideFlags of EditorWindows contains by default DontSave. Setting the flags to 0 ((HideFlags)0) i was able to save it without problems, but once i closed the window the asset got currupted and i can't even delete it in Unity (only in the explorer).
Your answer
Follow this Question
Related Questions
ScriptableObject does not serialize 0 Answers
Unity Not Loading 0 Answers
Serialization depth limit 7 exceeded 1 Answer
Abstract classes in a ScriptableObject 1 Answer
Save/load playerprefs 2 Answers