Legacy Documentation: Version 2018.1 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

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

Experimental: this API is experimental and might be changed or removed in the future.

GameObjectRecorder

class in UnityEditor.Experimental.Animations

/

Inherits from:Object

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

Submission failed

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

Close

Cancel

Description

Records the changing properties of a GameObject as the Scene runs and saves the information into an AnimationClip.

This class binds GameObject properties, records their values as they change in the running Scene, and saves the result in an AnimationClip. The recorded GameObject is called root in the class, and you can also bind the properties of any child of root.

See the following code example on how this class can be implemented and to set what gets recorded.

#pragma strict
public class RecordTransformHierarchy extends MonoBehaviour {
	public var clip: AnimationClip;
	private var m_Recorder: GameObjectRecorder;
	function Start() {
		// Create recorder and record the script GameObject.
		m_Recorder = new GameObjectRecorder(gameObject);
		// Bind all the Transforms on the GameObject and all its children.
		m_Recorder.BindComponentsOfType.<Transform>(gameObject, true);
	}
	function LateUpdate() {
		if (clip == null)return ;
		// Take a snapshot and record all the bindings values for this frame.
		m_Recorder.TakeSnapshot(Time.deltaTime);
	}
	function OnDisable() {
		if (clip == null)return ;
		if (m_Recorder.isRecording) {
			// Save the recorded session to the clip.
			m_Recorder.SaveToClip(clip);
		}
	}
}
using UnityEngine;
using UnityEditor.Experimental.Animations;

public class RecordTransformHierarchy : MonoBehaviour { public AnimationClip clip;

private GameObjectRecorder m_Recorder;

void Start() { // Create recorder and record the script GameObject. m_Recorder = new GameObjectRecorder(gameObject);

// Bind all the Transforms on the GameObject and all its children. m_Recorder.BindComponentsOfType<Transform>(gameObject, true); }

void LateUpdate() { if (clip == null) return;

// Take a snapshot and record all the bindings values for this frame. m_Recorder.TakeSnapshot(Time.deltaTime); }

void OnDisable() { if (clip == null) return;

if (m_Recorder.isRecording) { // Save the recorded session to the clip. m_Recorder.SaveToClip(clip); } } }

Properties

currentTimeReturns the current time of the recording. (Read Only)
isRecordingReturns true when the recorder is recording. (Read Only)
rootThe GameObject root of the animated hierarchy. (Read Only)

Constructors

GameObjectRecorderCreate a new GameObjectRecorder.

Public Methods

BindBinds a GameObject's property as defined by EditorCurveBinding.
BindAllAdds bindings for all of target's properties, and also for all the target's children if recursive is true.
BindComponentAdds bindings for all the properties of component.
BindComponentsOfTypeAdds bindings for all the properties of the first component of type T found in target, and also for all the target's children if recursive is true.
GetBindingsReturns an array of all the bindings added to the recorder.
ResetRecordingReset the recording.
SaveToClipSaves the recorded animation into clip.
TakeSnapshotForwards the animation by dt seconds, then record the values of the added bindings.

Inherited Members

Properties

hideFlagsShould the object be hidden, saved with the scene or modifiable by the user?
nameThe name of the object.

Public Methods

GetInstanceIDReturns the instance id of the object.
ToStringReturns the name of the GameObject.

Static Methods

DestroyRemoves a gameobject, component or asset.
DestroyImmediateDestroys the object obj immediately. You are strongly recommended to use Destroy instead.
DontDestroyOnLoadMakes the object target not be destroyed automatically when loading a new scene.
FindObjectOfTypeReturns the first active loaded object of Type type.
FindObjectsOfTypeReturns a list of all active loaded objects of Type type.
InstantiateClones the object original and returns the clone.

Operators

boolDoes the object exist?
operator !=Compares if two objects refer to a different object.
operator ==Compares two object references to see if they refer to the same object.

Did you find this page useful? Please give it a rating: