How to support undo for objects in .asset files

I’m creating an asset using the following code:

public static void CreateAssetGraph()
    var asset = ScriptableObject.CreateInstance<Graph>();
    AssetDatabase.CreateAsset(asset, AssetDatabase.GenerateUniqueAssetPath("Assets/NewGraph.asset"));
    AssetDatabase.SetLabels(asset, new string[] { "Graph" });

I want to support Undo for all the operations performed on this asset so I’m writing the following before each operation:

Undo.RecordObject(activeGraph, string.Format("Create {0} Block", blockShape.Name));

The issue is that, after I undo the operation, my object doesn’t seem to change.

I added handlers to ValidateCommand and ExecuteCommand events so that when I get a command name “UndoRedoPerformed” I execute:


I can see then in the .asset file that the undo was performed and correctly serialized. I tried using AssetDatabase.ImportAsset and AssetDatabase.Refresh and the version in memory never changes. If I close Unity and reopen the project, then the .asset is loaded correctly.

Am I missing something?

Thanks in advance,

I decided to create a simpler project to test these issues. The source is available at I’m still not happy with the editor window not updating when not in focus but I got most of it working.