- Home /
Determine difference between Undo and Redo operations
Hi all,
I'm using Undo.RecordObject to undo changes to a mesh and need to do a clean up after the user presses Ctrl-Z but can't determine the difference between this and Ctrl-Y.
The following code tells me that something happened but I can't find any extra info.
if (Event.current.type == EventType.ValidateCommand)
{
switch (Event.current.commandName)
{
case "UndoRedoPerformed":
Debug.Log ("What actually happened?");
break;
}
}
Thanks in advance for any help.
Answer by MakeCodeNow · Jul 07, 2014 at 12:02 AM
Unity's Undo is designed to be automatic. As long as you properly record all of the creation/parenting/changes, then Unity will handle the Undo and the Redo for you automatically. Catching the UndoRedoPerformed event using the string command name is pretty far into undocumented/unsupported territory, and should really only be used if you need to do something like reset a UI on Undo or Redo. I'm not aware of any way to get the list of changes for that Undo or Redo.
Thanks $$anonymous$$akeCodeNow, it does feel like I'm far into undocumented/unsupported territory here. Chris Herold suggested that there should be a separate UndoPerformed and RedoPerformed notification here back in early 2012 which would have saved me a lot of work.
Since I'm working with procedural modeling, and custom data, the only way to handle this that I can think of is to keep an array of vertices for each step of the creation process and compare these (point by point) to the current vertices to deter$$anonymous$$e if the user has stepped forward or backwards.
If the keystrokes weren't hidden from the custom editor when an Undo or Redo is performed then I could have just flagged the UndoRedoPerformed notification and checked for a Z or Y key press, but unfortunately this doesn't work. Thanks again for your take on this.
No prob. Another idea would be for you to not register with Unity undo and just have your own Undo and Redo button. That way you could keep your own modifier stack and avoid really gross, exhaustive comparisons just to see what's changed.
PS -please mark answer as accepted :)
Your answer
Follow this Question
Related Questions
Custom data for undo/redo action? 0 Answers
undo and redo 0 Answers
Repaint on Undo 5 Answers
Can my EditorWindow intercept Undo Redo Keyboard commands? 0 Answers
undo redo disabled 1 Answer