Editor Script not saving after first time playing

This is a very weird behavior. I have a very complex editor script and it seems like it will only save the first time I use it before I hit the play button. Here is my step by step.

  1. Create GameObject
  2. Attach A Script
  3. Open Editor Window
  4. Adjust setting in Editor Window
  5. Hit Play (everything is still there)
  6. Hit Play (to stop)
  7. Adjust setting
  8. Hit Play…the changes revert to Adjustment in step 4
  9. Go edit any script in my project
  10. Adjust settings in Editor Window
  11. Hit Play…everything saves again but only this time

I am using EditorUtility.SetDirty to save the info to my script attached to my GameObject. And I have Serialized every field and class, probably more than it needs. I will try to get a simplified example upload later.

I am adding an example package that is simplified version of what I am experiencing.
You can open the window when in Unity going Window > Test Editor


When variables are public they are shown in the Inspector.

The values given to the variables in the script will be used only the first time. After, you need to change them from the Inspector. Chnaging them in the script editor won’t alter them in the script. Only the constants will be changed from editor script.

I found a solution to my problem. It appears that I am loosing my reference to the MonoBehavior when I hit play. What i am doing is probably overkil but I am re finding the script OnEnable, OnSelectionChange, OnFocus, and OnHierarchyChange. That caused it all to work perfectly. I am sure this is not the optimal method of doing this but it works for now.