Undo.RegisterUndo Manual     Reference     Scripting  
Scripting > Editor Classes > Undo
Undo.RegisterUndo

static function RegisterUndo (objectToUndo : Object, name : string) : void

static function RegisterUndo (objectsToUndo : Object[], name : string) : void

Parameters

NameDescription
objectToUndo The object(s) you want to save undo info for.
name The name of the action to undo. Think "Undo ...." in the main menu.

Description

Register the state of one or more objects so the user can later undo back to that state.

@MenuItem("GameObject/Set Field of View")
static function Test () {
Undo.RegisterUndo (Camera.main, "Field of View Change");
Camera.main.fieldOfView = 50;
}

Note that only the actual objects passed as parameters are saved. For example, passing a game object will not save all its components or child objects. If you need to save the state of an entire game object, you can use EditorUtility.CollectDeepHierarchy on the game object to get all the objects that it contains and pass all those objects as objects to undo.

See Also: Undo.RegisterSceneUndo.