As you start creating animations, you’ll accrue many clips. Some GameObjects are going to have many animations, so you’ll need a way to control which animations run when. It’s possible to do this through code, but why would you go to the hassle when Unity provides a tool that makes this easy?
Meet the Animator.
You can think of the animator as the director in a movie. It runs around giving orders of which animations to play when.
For instance, when a character stands idle, the animator could order an animation to move the head and portray breathing and fidgeting. When a character’s horizontal speed increases, the animator could order a walking animation; once speed surpasses a defined threshold, the animator could order a running animation.
With the animator, you define the conditions and their animation relationships. Then, in essence, the game takes care of itself.
Note: This tutorial is part of a collection that teaches Unity development from the ground up. You can read the entire series over here. This series is free and does not require any account creation. All assets are provided. If you find it useful, feel free to buy me a coffee.
Accessing the animator
To get started working with the animator, click Window ▸ Animation ▸ Animator to open the Animator window.
Note: When you first start working with Unity, you may confuse the Animation and Animator windows. Try a little memory trick: The anima-tion window is where you do crea-tion. The animat-or window is where you’re an organiz-er.
You’ll probably see an empty window because you didn’t select a GameObject that has an animator component attached to it.

In the Hierarchy, click BobbleArena and check if you see the following in the Animator window:

You’ll see that the Walls
animation is already present in the controller. Any new animation clips are added to the current animator controller automatically.
Each rectangle indicates an animation state:
- The green rectangle is the entry point of the animator.
- The orange rectangle indicates the default state; it’s always played first.
- The arrows indicate transitions between states.
By scrolling your middle mouse wheel up, you can zoom in on the states. Likewise, scrolling down zooms out. Pressing and holding the middle mouse wheel allows you to pan over the states. These shortcuts are useful when you have a lot of states onscreen at once.
Play your game and move the hero until you can see the lowered walls. The animation loops endlessly.

Watch the animator as it plays to see the animation’s progress.

Configuring an animation state
In the Project window, click the Animations folder and select the Walls animation. In the Inspector, uncheck Loop Time.

That’s how you override the default — no loop for you!
Unfortunately, “Walls” isn’t a very descriptive name. Click the Walls state in the Animator and look at the Inspector to see all the available properties. You’ll learn and change a bunch of these throughout this book.
For now, change the name from Walls to WallsLower. That’s it in here.

Notice that the state reflects the updated name.

Being that you have a WallsLower
state, you need a WallsRaise
state. You could create a new animation, but since this animation is very similar to the WallsLower
animation (just reversed), I’ll show you a shortcut.
Creating an animation state
Right-click in the Animator, select Create State and then Empty.

You’ll now have a new empty state.

Select this new state and name it WallsRaise in the Inspector. Next, drag the Walls animation from the Animations folder to the Motion property. Finally, set the speed to -1
.

The Motion
property references the actual animation clip. In this case, you’re using the same animation clip that you used in WallsLower
. The Speed
property lets you designate how fast the clip will play. Setting the speed to 1
indicates that it will play at normal speed. Higher numbers make the clip run slower, whereas lower numbers make it run faster.
Why -1? Negative numbers play the clip in reverse. In this case, you’re using the same clip but playing it in reverse at normal speed.
You need one more state: An idle state. Open the Animation window, making sure the BobbleArena is selected in the Hierarchy. You’ll see the name of the currently displayed animation in the property list, which should be walls.
Click Walls and select Create New Clip… from the drop-down.

Give it the name ArenaIdle.anim. That’s right — your animation clip comprises an empty animation. Although you can create a state with no associated animation, Unity will do weird things that might ruin your plans. At times, it helps to play it safe and make an animation clip for the idle state, even if it’s empty.
Your animator should look something like this:

You need to organize it, and you’ll do that through transitions.
Where to go from here
Animators and animations can be perplexing at first due to their names. Thankfully, the confusion period is brief. You’ll be able to tell the difference in no time.
At this moment, there is no way for you to move between the various animation states. Thankfully, Unity has you covered by way of animation transitions. You’ll put these to work in the next tutorial.
Discover more from Jezner Blog
Subscribe to get the latest posts sent to your email.