Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

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

Undo

Namespace: UnityEditor

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

ClearUndoRemoves aall Undo operation for the identifier object registered using Undo.RegisterCompleteObjectUndo from the undo stack.
CollapseUndoOperationsCollapses all undo operation up to group index together into one step.
DestroyObjectImmediateDestroys the object and records an undo operation so that it can be recreated.
GetCurrentGroupUnity automatically groups undo operations by the current group index.
IncrementCurrentGroupUnity automatically groups undo operations by the current group index.
PerformRedoPerform an Redo operation.
PerformUndoPerform an Redo operation.
RecordObjectRecords any changes done on the object after the RecordObject function.
RecordObjectsRecords multiple undoable objects in a single call. This is the same as calling Undo.RecordObject multiple times.
RegisterCreatedObjectUndoRegister an undo operations for a newly created object.
RevertAllDownToGroupPerforms all undo operations up to the group index without storing a redo operation in the process.
RevertAllInCurrentGroupPerforms the last undo operation but does not record a redo operation.
SetTransformParentSets the parent of transform to the new parent and records an undo operation.