Implement the Avatar Recorder
Last updated
Last updated
Now that you have Unity recognizing your headset and the Avatar Recorder in your assets folder, we can begin to use it.
The Avatar Recorder package comes with a demo scene. So open that up in Unity and take a look around, pick it apart and learn.
The XR Interaction Toolkit demo scene is located at:
XR Interaction Toolkit Demo - Assets/AvatarRecorder/XRTooklit/Recorder_XRI
Otherwise, the main component in the package is named respectively as the 'AvatarRecorderV3' script. Place this script onto the root of the player's VR avatar, the one you wish to record.
On the AvatarRecorderV3 script, there is a slot for a 'ClonePrefab'. Here is where you place a copy of an avatar that you wish to take in the recording. When the recording is finished, it's this clone prefab that will be instantiated and it's this prefab that will be used on playback. It is important that this prefab has the same hierarchy as the VR avatar that the recording originates from. Also, in my own projects, I tend to copy the VR avatar and strip off all of the colliders and rigidbodies leaving just the visual aspects from the clone prefab. This removes the possibility of the clone colliding with the world (unless that is a mechanic that you want). I also remove all other tracking scripts on the clone so they don't interfere with the animation’s playback.
That's it! The rest of the slots will auto-populate on start. Easy right?
Press play in the inspector and hit the 'Start Recording' when you're ready, the 'Stop Recording’ when you're done, and the 'Play Recording' when it's time to play. The recorder plays back the last recording.
Here's what's happening in the background:
When the 'Start Recording' button is pressed, the Recorder starts recording the change of the data on itself, and every child recursively then saves it as an animation clip. At the same time, starts taking input from the mic to save it as an audio clip.
When the 'Stop Recording' is pressed, the Recorder ends both audio and animation clip recordings and creates a file under their respective folder name (make sure the path exists beforehand).
When the 'Play Recording' button is pressed, the Recorder then creates an instantiation of the clone prefab, and checks to see if there is an Animator, a Playable Director, and an Audiosource component on the prefab or its children, if not then it adds those components. After that, it creates a new timeline and loads in the animation clip and audio clip as a timeline asset, then plays the director. The timeline is then saved as a file under its respective save path.
By default the save paths are:
Animations - "Assets/AvatarRecorder/AvatarRecorder/Clones/Animations/"
AudioClips - "Assets/AvatarRecorder/AvatarRecorder/Clones/AudioClips/"
Timelines - "Assets/AvatarRecorder/AvatarRecorder/Clones/Timelines/"
To use the recordings as a persistent clone in your project, you need to build it in your hierarchy. This is easy. Once you have recorded some clips that you like:
(It is good practice to rename the Animation Clip, AudioClip, and Timeline files so they don't get overwritten by future recordings.)
Place a clone prefab into your hierarchy as a new object. Make sure that there is an Animator, an Audiosource, and a Playable Director component somewhere on it or its children.
That's it! You can also create a new timeline asset and populate it with other or many animations and audio clips as needed.
Good luck and have fun!
Find the timeline that was created from your recording and place it into the Playable Director component under its Playable asset slot.