LanguageEnglish
  • C#
  • JS

Script language

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

Undo.RecordObject

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

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

Parameters

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.

#pragma strict
function Start() {
	Undo.RecordObject(Selection.activeTransform, "Edit Transform");
	Selection.activeTransform.position = Vector3(0, 0, 0);
}
using UnityEngine;
using UnityEditor;
using System.Collections;

public class ExampleClass : MonoBehaviour { void Start() { Undo.RecordObject (Selection.activeTransform, "Edit Transform"); Selection.activeTransform.position = Vector3(0, 0, 0); } }
#pragma strict
// 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(LookAtPoint)
class SnapshotTargetEx extends Editor {
	function OnSceneGUI() {
		var lookAtScript: LookAtPoint;
		EditorGUI.BeginChangeCheck();
		var pos: Vector3 = Handles.PositionHandle(target.lookAtPoint, Quaternion.identity);
		if (EditorGUI.EndChangeCheck()) {
			Undo.RecordObject(target, "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);
		}
	}
}
// 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 : Editor {

void OnSceneGUI () { LookAtPoint lookAtScript; EditorGUI.BeginChangeCheck (); Vector3 pos = Handles.PositionHandle(target.lookAtPoint, Quaternion.identity); if (EditorGUI.EndChangeCheck ()) { Undo.RecordObject (target, "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); } } }