Custom Editor, variables declared in custom editor script resets

When creating a variable in a class that extends Editor, the variables are not serialized and it resets back to the default values. In this case, I want to display a enum in the inspector that is declared in the ExampleEditor script. The values go back to the default after it looses focus. This is what I have so far:

using UnityEngine;
using UnityEditor;
using System.Collections;

[CustomEditor(typeof (Example))]
public class ExampleEditor : Editor {
    private enum Things{
        Thing1,
        Thing2,
        Thing3
    }
    public ItemTypes currentType;

    public override void OnInspectorGUI() {
        currentType = (ItemTypes)EditorGUILayout.EnumPopup("Item Type", currentType);
    }
}

I understand that you can declare it in the Example script and not it the ExampleEditor script. However, This enum is not needed inside the Example script and I only want it in the Example editor

I’m pretty sure that whenever you click an object in the inspector, a new Editor for that object is created. It would be a really bad idea to serialize the editors for each object, as that’d double the amount of data serialized.

You could set the currentType static. Then it won’t change before you go in and out of play mode. If that’s not an option (you want to save different values for different instances), you’ll have to save the enum on the object itself, or create some kind of dictionary that maps from the instance ID of the objects to their current value.

I think having an extra int on your script will be a lot less pain.