Custom Inspector Undo

I have the following in a very simple custom editor. If I change the value and hit ctrl+z, it does not undo the value change, but instead reverts to the last operation on the undo stack (Selection Change). What do I need to do to this code to make it properly work with ctrl+z?

If I leave it using the default inspector, ctrl+z works as it should.

            public override void OnInspectorGUI()
            {
                _target.Field = EditorGUILayout.FloatField("Field Value:", _target.Field);
    }
EditorGUI.BeginChangeCheck()

float newValue = EditorGUILayout.FloatField("Field Value:", _target.Field);

if (EditorGUI.EndChangeCheck()) {

    Undo.RecordObject(_target, "Set Field Value");

    _target.Field = newValue;
}
1 Like

Thanks, this worked, but Undo.RecordObject does not work for me. I have to use Undo.RegisterUndo for some reason.