- Home /
How to prevent Editor script variables resetting at runtime
Variables and arrays are getting reset in my custom editor script when I play the scene. How can I make these variables persistent even when quitting and re-opening Unity?
Answer by whydoidoit · Nov 24, 2012 at 05:10 PM
You need to use EditorPrefs for editor variables. Make them static and they will persist inside the same session, but not after a code edit.
Answer by nicloay · Nov 26, 2012 at 10:28 AM
Easiest way to populate default values in MonoBehaviour.Reset method
I've been using the EditorPrefs inside Awake(), which seems to have been working well. $$anonymous$$y only issue is if I modify the editor script it will empty the variables but I don't think I have any way of detecting if the script simply compiled because neither Awake() or Reset() will run after compilation unless I de-select and re-select the gameObject.