Hi!
In the 2017.1 comes a new editor feature: GameObjectRecorder. It allows to record any properties on a GameObject and its children.
Please keep in mind that this feature is experimental. We know there is lots of room for improvement, but we would first like to get feedback from you, our user, in order to identify use cases that are meaningful/useful to you. This feedback will really help us decide how to evolve this feature, moving forward.
In the example below, there is one root GameObject and all the other GameObject are children of this “Scene Root”. On this Scene Root there is a script using a GameObjectRecorder. This GameObjectRecorder is set up to record the transform changes on the Scene Root and all its children. Once the user stops the recording, it saves everything that’s been recorded into an animation clip.
Click on this link to see the result:
Here is the code used to produce this example:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.Experimental.Animations;
public class HierarchyRecorder : MonoBehaviour
{
// The clip the recording is going to be saved to.
public AnimationClip clip;
// Checkbox to start/stop the recording.
public bool record = false;
// The main feature: the actual recorder.
private GameObjectRecorder m_Recorder;
void Start()
{
// Create the GameObjectRecorder.
m_Recorder = new GameObjectRecorder();
m_Recorder.root = gameObject;
// Set it up to record the transforms recursively.
m_Recorder.BindComponent<Transform>(gameObject, true);
}
// The recording needs to be done in LateUpdate in order
// to be done once everything has been updated
// (animations, physics, scripts, etc.).
void LateUpdate()
{
if (clip == null)
return;
if (record)
{
// As long as "record" is on: take a snapshot.
m_Recorder.TakeSnapshot(Time.deltaTime);
}
else if (m_Recorder.isRecording)
{
// "record" is off, but we were recording:
// save to clip and clear recording.
m_Recorder.SaveToClip(clip);
m_Recorder.ResetRecording();
}
}
}
Once saved in a clip, to play it back you can duplicate your scene object, remove any physics components there might be on the duplicated objects (to prevent conflicts with the animation), and drag and drop the clip on the scene object.
Features:
- /!\ Only work in Editor scripts for now
- Can record all the properties of a GameObject
- Can record the properties of one component of a GameObject
- Can record one specific property of a GameObject
- Can record recursively on all the GameObject’s children
- Save the recording in an animation clip (.anim)
- Compute the appropriate tangents
- Reduce the keys
Here is the link to the API: Unity - Scripting API: GameObjectRecorder