EditorWindow: How to Serialize variables after PLay

So I’ve searched countless of times for a solution to this problem, but I wasnt really able to find or understand how to work (around?) this. In practise:

I have an EditorWindow which has a variable of an object I want to make GUI of, for example:

class MyEditorWindow extends EditorWindow{

  var targetObject:Foo;

  function OnGUI(){

     targetObject.myVar = FloatField(targetObject.myVar);

     if (GUI.changed)

  static function OpenWindow(targetObject:Foo){

     var window = GetWindow(MyEditorWindow);
     window.targetObject = targetObject;

All works good etc. Then I hit Play and everything has been decoupled. I still see my EditorWindow GUI and change the float for example from the control, but it doesnt refer to the targetObject anymore. So anyone know hot to work this?

Thanks, I believe I was prety clear on the issue :slight_smile: and hopefully other get help as well.

(PS: Foo is MonoBehaviour)

I know this is kind of old, but I was experiencing the same problem and I found the solution.

Any variables you want to persist after you press play need to be serialized by Unity. Since it doesn’t really make sense to have public variables on an EditorWindow, this means prefacing your private variables with the [SerializeField] attribute. This allows Unity to store the value and reload it after you finish playing.