Quantcast
Channel: Latest Questions by Veehmot
Viewing all articles
Browse latest Browse all 38

Creating persistent object in Edit mode

$
0
0
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

Viewing all articles
Browse latest Browse all 38

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>