Hi,
I’m creating an asset using the following code:
[MenuItem("Assets/Create/Graph")]
public static void CreateAssetGraph()
{
var asset = ScriptableObject.CreateInstance<Graph>();
AssetDatabase.CreateAsset(asset, AssetDatabase.GenerateUniqueAssetPath("Assets/NewGraph.asset"));
AssetDatabase.SetLabels(asset, new string[] { "Graph" });
AssetDatabase.SaveAssets();
}
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:
EditorUtility.SetDirty(activeGraph);
AssetDatabase.SaveAssets();
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,
Antao