EditorWindow loses public data when closed (not when Unity is closed)

I have a rather odd problem. I have an EditorWindow derived class that is marked as System.Serializable and has a few properties. One of those properties is another class (also serializable and works fine) and other standard types such as string and bool, also marked as SerializeField and public (I know the first is redundant).

Every problem I see described on here reports issues entering then exiting Play Mode, and Restarting Unity. I am familiar with the issues of Serialization (and have read the mega thread) but I do not have those issues. All properties are retained fine in those two situations.

However, whenever I close the Window my editor is running in (via the Close Tab option) and re-open it using my Init method which simply calls EditorWindow.GetWindow(“WindowName”) it always loses all the public properties.

I am stumped. My class name also matches my script name, which I know can also cause issues.

@steddyman

Try to store reference in static variable

private static MyObject _myObjectReference;

this value will be losed whenewer you exit PlayMode and restart Unity, but it’ll be stored when EditorWindow instance destroyed (i.e. closed)

To keep data all the time you may store it in ScriptableObject, store instance of this SO on the Resources as a separate file and load it to _myScriptableObjectReference if _myScriptableObjectReference is null