Undo
Description

Lets you register undo operations on specific objects you are about to perform changes on.

The undo system in Unity works by saving the state of one or more objects before performing a change on those objects. It is similar to taking a backup. To undo the change later, the saved state is restored. Since this reverts the objects to the state they had before performing the change, it will be as if the change never happened.

For instant changes to one or more objects, simply call functions RegisterUndo or RegisterSceneUndo before performing the change that it should be possible to undo.

This is all that needs to be done. Unity will automatically handle Undo and Redo for you after that. PerformUndo and PerformRedo should normally not be used unless you want to create your own user interface to the undo system in addition to the user interface Unity already provides.

Using RegisterUndo is most efficient for actions that change one or more objects. RegisterSceneUndo is slower and requires more memory, but it can be used in all cases, and is required for actions that create or destroy objects.

Certain operations, such as dragging, consist of many small incremental changes. Typically it is not desired to create an undo step for each of these small changes. For example, if the user performs an undo after a dragging operation, it is expected that the object is reverted back to the state it had before the dragging started. The functions SetSnapshotTarget, CreateSnapshot, and RegisterSnapshot are available to handle cases like this.
Static Functions
ClearSnapshotTarget Clear the snapshot target set with SetSnapshotTarget.
CreateSnapshot Save the current state of all objects set with SetSnapshotTarget to internal snapshot.
PerformRedo Perform an Redo operation.
PerformUndo Create a snapshot of objects in a temporary buffer.
RegisterCreatedObjectUndo Register the state of a Unity Object so the user can later undo back to that state.
RegisterSceneUndo Register the state of the entire scene so the user can later undo back to that state.
RegisterSnapshot Register the snapshot state made with CreateSnapshot so the user can later undo back to that state.
RegisterUndo Register the state of one or more objects so the user can later undo back to that state.
RestoreSnapshot Restore the snapshot state made with CreateSnapshot.
SetSnapshotTarget Set the objects modified by the GUI or Handles so they can undo properly.