- Home /
Why does my ExecuteInEditMode script lose its initial inspector value?
Hey all,
this is my first time using ExecuteInEditMode and I'm having one last issue.
So I have a script with the [ExecuteInEditMode] tag above it.
In the script is a public float that can be changed in inspector.
During play the value is changed, but after exiting play mode the value stays the same instead of resetting like it normally would.
Any one know how to get it to preserve its editor value?
EX: In edit mode inspector float value =0; Hit play mode, code changes value=1; exit play, value still =1.
I tried using the EditorUtility.SetDirty() but it didn't seem to do anything.
Answer by Xarbrough · Jan 24, 2016 at 09:02 PM
It is not (easily or built-in) possible to preserve inspector serialized values through play mode. The only way to do this, would be to write the values to a file and load them when stopping playmode. There are some solutions for it on the Asset Store, but to come back to the question, this has nothing to do with ExecuteInEditMode, which is just an attribute to tell Unity to call Update() every time, the Editor updates it's views.
Your answer
![](https://koobas.hobune.stream/wayback/20220611235616im_/https://answers.unity.com/themes/thub/images/avi.jpg)