Unity: Setting up animations

Benjamin Dendas
4 min readAug 22, 2020

When you are making a 2D game, the animations in your game are very important as a bad animation will make your game look bad or not as professional as you would like.

In Unity, it is very easy to create animations based on the assets that you use. The majority of the quality of your animation is based on the quality of the sprites that you use.

Every animation need a set of sprites in order to make the animation effect feel real to the gamer.

Making an animation

In Unity, import the assets for the animation you would like to make.
We will be using the Male Character asset from the toon character set from Kenney.nl.

Male Character set

Once you have imported the assets, creating the actual animation is nothing more then drag and dropping the correct assets in the hierarchy view.

Let’s create a walking animation with these assets. select the walk assets, going from character_malePerson_walk0 until character_malePerson_walk7 and drag them in the hierarchy view.

Save the animation as male_run.anim, this will create 2 new files:

  • man_walk.anim
  • character_malePerson_walk0.controller

This is everything we needed to do in order to create an animation in Unity. Let’s look how we can make animations change depending on changes ingame by using an animator controller.

Setting up a 2D object

After you have made an animation, it is time to apply this animation to a sprite. However, we need to do a little bit of setup before we can do that. Let’s start by creating a new gameobject that will contain our sprite.

Create an empty object

In this empty object, add a new sprite which will be used to show the character on the screen.

Add a new Sprite

At the moment, when we start the game we won’t see anything on the screen. This comes because we don’t have any asset set up by default for our newly created character object. Let’s set the idle assets as the default for the character. Look for the idle asset in the assets folder and drag it in the Sprite slot on the Sprite renderer component of the Sprite object.

This will automatically show the character in the scene viewer.

The idle asset in the sprite renderer

Creating an animator controller

In order to link an animation to a 2D sprite, we need a few things set up in order to play animations.

The first thing we need is an animator controller in our scene.

Creating an animator controller from the context menu
The animator controller

When you double click on the Animator Controller, the animator window pops open.

Animator window in Unity

The next step to add our animation to the animator controller. Look for the animation that you made in the make an animation section and drag it into the animator window.

Add the walk animation to the animator

The animator automatically attaches the man_walk animation to the entry block. This is because an animator needs a default animation that will be played by default.

The second thing we will need to do is adding an Animator component to our 2D sprite. This will allow us to attach the Animator Controller to our character.

Adding an Animator to the component

After creating the animator component, drag the animator controller in the Controller slot of the Animator.

Linking the Animator Controller to the Animator

When you hit play now, the scene will start and our character will be running.

This is everything you need to do in order to get animations to play on your 2D sprite.

--

--

Benjamin Dendas

Product-Minded individual with a strong interest in product development and strategy, loves to learn and talk.