Legacy Documentation: Version 4.6(go to latest)
Language: English
  • C#
  • JS
  • Boo

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Undo

Namespace: UnityEditor

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

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

The Undo system stores delta changes in the undo stack. Undo operations are automatically combined together based on events Eg. mouse down events will split undo groups.

Undo operations store either per property or per object state. This way they scale well with any scene size. The most important operations are outlined below.

Modifying a single property:

        Undo.RecordObject (myGameObject.light, "Set Light Range");
myGameObject.light.range = 5;

Adding a component :

Undo.AddComponent<RigidBody> (myGameObject);

Creating a new game object:

var go = new GameObject ();
Undo.RegisterCreatedObjectUndo (go, "Created go");

Destroying a game object or component:

        Undo.DestroyObjectImmediate (myGameObject);

Changing transform parenting:

        Undo.SetTransformParent (myGameObject.transform, newTransformParent);

Static Functions

ClearUndo Removes aall Undo operation for the identifier object registered using Undo.RegisterCompleteObjectUndo from the undo stack.
CollapseUndoOperations Collapses all undo operation up to group index together into one step.
DestroyObjectImmediate Destroys the object and records an undo operation so that it can be recreated.
GetCurrentGroup Unity automatically groups undo operations by the current group index.
IncrementCurrentGroup Unity automatically groups undo operations by the current group index.
PerformRedo Perform an Redo operation.
PerformUndo Perform an Redo operation.
RecordObject Records any changes done on the object after the RecordObject function.
RecordObjects Records multiple undoable objects in a single call. This is the same as calling Undo.RecordObject multiple times.
RegisterCreatedObjectUndo Register an undo operations for a newly created object.
RevertAllDownToGroup Performs all undo operations up to the group index without storing a redo operation in the process.
RevertAllInCurrentGroup Performs the last undo operation but does not record a redo operation.
SetTransformParent Sets the parent of transform to the new parent and records an undo operation.