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?