Custom inspector values are not saving to .unity file...

Hey there, I hope this problem isn’t too much of a bother…

Basically when I create a field in a custom inspector for a value, in this test case an int, then change that in the custom inspector, when saving the scene/.unity file it doesn’t save the data:


Here’s the example code. The class/script’s name is O_Lists. This is attached to a game object:

public class O_Lists : MonoBehaviour {
    [SerializeField]
    public int TestInt;
}

In the editor script:

[CustomEditor(typeof(O_Lists))]
public class Editor_Inspectors_OLists : Editor {

    O_Lists o_Lists;
  
    void OnEnable() {
        o_Lists = (O_Lists)target;
    }
  
    public override void OnInspectorGUI() {
      
        DrawDefaultInspector ();
  
        EditorGUILayout.BeginHorizontal ();

        EditorGUILayout.LabelField("TestInt: ");

        o_Lists.TestInt = EditorGUILayout.IntField (o_Lists.TestInt);

        EditorGUILayout.EndHorizontal();
  
    }
  
}

Here’s a (very quick) video of the problem:

I fixed it with adding in the following at the end of the OnInspectorGUI() method:

EditorUtility.SetDirty (scriptReferenceGoesHere);

Sorry for wasting your time. : /