So I’ve been working creating a dialogue editor in graph view. I would like to be able to undo and redo action. Currently unable to do that. How would I go about implementing this?
It’s an old question, but decided to answer it because it would’ve been useful to know myself.
You can just use the Unity Undo system, but you have to do a bit more manual work to make it work properly. With Unity’s Undo.RecordObject you can record the state of an object and whenever you press undo, Unity will automatically go back to the previous stored state in the Undo stack.
When working with custom editor windows and graphviews, you will most likely store all your data in a scriptable object and the state of this scriptable object can be recorded. However when just pressing undo the data in your scriptable object will change, but your graphview will not yet be reloaded.
So you can listen to Undo.undoRedoPerformed to reload your graphview every time an Undo or Redo is performed.
You now just have to decide which action you want to make undoable, and before every action you want to undo, call Undo.RecordObject. You can listen to events like graphViewChanged and deleteSelection to be able to make the built-in behaviour undoable