How do I support Undo without using properties?

Unity’s property drawers and stuff are great, but it’s just flipping impossible to get it to play nicely with custom classes. I “have to” support Undo for things submitted to the asset store, but as far as I can tell, Undo doesn’t work at all. Please instruct.

	public override void OnInspectorGUI() {
		EditorGUILayout.IntField(1); // whatever, many fields go here
		if ( EditorGUI.EndChangeCheck() ) {
			Undo.RecordObject(target,"Animated Sprite change");


This is inconsistent and bad at registering undos. The first change I make is ignored. I even have it recordobject in OnEnable. Is there an example somewhere of how to actually do this? I’ve never been able to get Unity to register my undos the way undos work in anything else.

SerializedProperties support undo by default.

using UnityEngine;
using UnityEditor;
using System.Collections;

public class MyEditor : Editor {
	SerializedProperty myInt;
    SerializedProperty myCustomClass;
	void OnEnable(){
		myInt = serializedObject.FindProperty("myInt");
            myCustomClass = serializedObject.FindProperty("myClass");
	public override void OnInspectorGUI(){
		serializedObject.Update(); //don't forget this
        EditorGUILayout.PropertyField(myCustomClass, true); //shows children too
		serializedObject.ApplyModifiedProperties(); //or this

public class NewBehaviourScript : MonoBehaviour {
	public int myInt;
    public MyClass myClass;

    void Reset(){
        myClass = new MyClass();

public class MyClass{
    public string aString;

Any change made to myInt, or within myClass, will be Undoable.