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.RecordObject

static function RecordObject(objectToUndo: Object, name: string): void;
static void RecordObject(Object objectToUndo, string name);
static def RecordObject(objectToUndo as Object, name as string) as void

Description

Records any changes done on the object after the RecordObject function.

Almost all property changes can be recorded with this function. The transform parent, AddComponent, object destruction can not be recorded with this function, for that you should use the dedicated functions.

Internally this will create a temporary copy of the objects state and at the end of the frame Unity will diff the state and thus detect what exactly has changed. The changed properties are then recorded on the undo stack. If nothing has actually changed (Binary exact comparison is used for all properties), no undo operation will be stored on the stack.

        Undo.RecordObject (Selection.activeTransform, "Edit Transform");
Selection.activeTransform.position = Vector3(0, 0, 0);
no example available in C#
no example available in Boo
	// Editor Script Side
	// Create a position Handle and make the target always look at the position handle.
	// This is an editor Script, this should go inside the Editor Folder.

[CustomEditor (typeof(LookAtPoint))] class SnapshotTargetEx extends Editor {

void OnSceneGUI () { LookAtPoint lookAtScript;

EditorGUI.BeginChangeCheck (); Vector3 pos = Handles.PositionHandle(target.lookAtPoint, Quaternion.identity); if (EditorGUI.EndChangeCheck ()) { Undo.RecordObject ("Move point"); target.lookAtPoint = pos;

// Make sure to call SetDirty otherwise the inspector will not know that the script properties were modified EditorUtility.SetDirty (target); } } }