Is there a way to Undo.RecordObject on a System.Object?

I have a Usable MonoBehaviour, that has a list of UsageEntry which is a Serializable regular C# class.

public class UsageEntry
	[SerializeField] private string scene;
	[SerializeField] private List<string> triggers = new List<string>();
	public string Scene { get { return scene; } set { scene = value; } }
	public List<string> Triggers { get { return triggers; } }

There are places in my editor code, where I make changes to the entries, mainly add/remove from the string list of triggers. I want the undo system to be able to revert those changes.

Undo.RecordObject take a UE.Object so I can’t pass it the entry I’m modifying.

Also, it seems that it won’t snap back if I pass it the Usable component instead, i.e.

	Undo.RecordObject(usableItem, "Updating item's trigger name");
	usableItem.UpdateTriggerName(previousName, currentName);

Any ideas? (other than to make my UsageEntry class a ScriptableObject)


Strange, i did almost exactly the same just now - it worked perfectly… Maybe it’s the way you store the UsageEntries in your component class. Or it is because I made all data public.

EDIT: Works fine with [SerializedField] too, so I guess the problem lies within Usable.