Animate GameObjects using Timeline
This is just a quick article on how we can animate GameObjects using the Timeline in Unity. This offers a different and potentially more convenient workflow for animating GameObjects without necessarily needing to go through the usual process of creating an Animator, Animator Controller, and Animations individually.
With the Timeline open and an object with a Playable Director selected in the hierarchy, we can right click on the left column and create a new Animation Track.
Once we’ve done this, all we need to do to start using this track is to drag a GameObject (any GameObject we’d like to animate) straight into the Animator slot. Unity will helpfully give us the option to create an Animator on this object if there isn’t one already, and once this is done we can then click the red record button to start recording an animation.
As a quick note, I’ve found there’s a chance the row in the right column won’t turn red and display ‘Recording…’. This appears to be a bug in the editor, and I’ve personally found changing the Unity Editor’s layout (perhaps over to Default specifically) lets me record as intended.
Once this is recording, we can then select the object we want to animate, move the slider to the time/frame when we want to set a keyframe, and do so by (for instance) changing a value on the object’s Transform component. I believe we can also select multiple objects in this view, so we could, for instance, change the alpha value on several UI objects/images at once in this mode.
When we’re done, we can stop the recording by clicking the red record button once again. If we’re not quite happy with the animation or timings when we preview it using the Timeline, try double clicking on the appropriate row in the right column. This should then open up the traditional Animation dope sheet, letting us reposition or delete any of the keyframes we’ve made (as well as create new ones should we choose).
Equally, another thing we can do with an Animation Track is to take a pre-existing Animator, drag it into the slot, and then right click in the right column to ‘Add From Animation Clip’. We can then position and trigger this animation at the appropriate moment within, say, one of our cutscenes.
So just to recap: the Animation Track can let us trigger and control the timings of pre-existing animations, as well as to create new animations for GameObjects on the fly. This can make a pretty versatile tool when it comes to moving cameras, triggering animations on actors, creating fade transitions, and more 😄