As the documentation for **[EditorUtility.IsPersistent][1]** says:> Returns false if the object lives in the scene. Typically this is a game object or component but it could also be a material that was created from code and not stored in an asset but instead stored in the scene.
That's right, I'm creating a material from code, inside an **EditorWindow** class. How to make it persist and save to disk?
- **[SerializableField]** doesn't work.
- Setting the variable to **public** doesn't work.
- **[EditorPrefs][2]** can't help me, because it's only for value types.
- Any other option?
To clarify, I want to retain the variable reference upon closing **Unity3D** and opening the project again, I don't even know if it's possible.
Update
======
I just followed instructions found [here][3], and created the material on disk using **[AssetDatabase][4]**. Although the materials effectively are stored on **Assets**, the reference itself is lost, so I have to load them everytime in my **EditorWindow**.
To illustrate this point, I uploaded 2 screenshots:
In this, we can see that the materials are loaded, and **IsPersistent** returns *true* for all.
![http://i.imgur.com/zStuZ.png][5]
I restart **Unity3D**, and now the references are gone! But the materials are still in the **Assets** folder.
![http://i.imgur.com/XME88.png][6]
[1]: http://unity3d.com/support/documentation/ScriptReference/EditorUtility.IsPersistent.html
[2]: http://unity3d.com/support/documentation/ScriptReference/EditorPrefs.html
[3]: http://answers.unity3d.com/questions/119978/how-do-i-have-an-editorwindow-save-its-data-inbetw.html
[4]: http://unity3d.com/support/documentation/ScriptReference/AssetDatabase.html
[5]: http://i.imgur.com/zStuZ.png
[6]: http://i.imgur.com/XME88.png
↧