As the documentation for EditorUtility.IsPersistent 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 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, and created the material on disk using AssetDatabase. 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.
I restart Unity3D, and now the references are gone! But the materials are still in the Assets folder.