Unity Custom Editor - save value

This question has been asked, but the answers I have come across do not work for me, so I will ask it again. I have a class similar to this:

public class MyClass : MonoBehavior
{
   public int foo; 
}

I also have an editor for this class, like so:

[CustomEditor(typeof(MyClass))]
public class MyEditor : Editor
{
  private MyClass myClass;
  public int editInfo;

  public override void OnInspectorGUI ()
  {
     DrawDefaultInspector ();

     myClass = (MyClass)target;
     editInfo = EditorGUILayout.IntField("Edit Info: ", editInfo);

     if(GUILayout.Button ("edit class"))
     {
        editClass();
     }
  }

  public void editClass()
  {
      myClass.foo += editInfo;
  }
}

My problem is twofold : Firstly, Upon hitting the play button in the editor, Unity resets the editInfo field in my custom Editor. Secondly, although the changes are kept in my Dummy class (MyClass), if I implement this on a real class (too large to show here, but the functionality is the same), the value reverts.

I have tried Undo.RecordObject() and I have added the SerializeField property to all possible places where it could have any meaning. What am i doing wrong?

Assume that nothing in an Editor class is permanent. It can change from frame to frame. If you assume anything will be persistent, you’re setting yourself up for failure.

Also, don’t store the myClass as a class-scope variable. It should remain method-scope or use an automated getter property.

Finally, keep the data in the data class. “editInfo” is indeterminate simply because it’s in an editor class. As soon as you move it to the source data class, it will be more persistent.