Unity3D: Animating 2D Sprites

Using the animation system in Unity is quite simple. Let’s go through animating a character in its walking-down state for today.

Sprite Configuration

Let’s take a look at a character sprite sheet I created.

Meet Daelocke. The protagonist for a game I want to develop. You can use this sprite sheet if you want to practice with me!

We want to drag this into our “Sprite” folder under assets. If you don’t have a sprite folder, create one! It’s always a good practice to keep your files cleaned up from the Assets folder.

Select the sprite sheet. We should see options to manipulate the sprite sheet in the inspector:

For 2D sprites, make sure the Texture Type is “Sprite (2D and UI).” For sprite sheets, make sure the Sprite Mode is “Multiple.” Pixels Per Unit is a preference. A 16 pixels per unit means that 1 unit in Unity will equal 16 pixels.

Head down to Filter Mode and select “Point (no filter)” if you are using pixel art. It will keep the edges of the sprites sharp.

The Max Size scales the quality of the sprites. Rule of thumb, always scale double the size. To find out the size, you can click on the sprite sheet, and at the bottom of the inspector, the size is displayed.

The Max size of the sprite sheet is 228. The rule of thumb is to double it in the Max Size option. 512 would be the best option closest to 456 (228 x 2).

Once we are all set up in the inspector, we press the “Sprite Editor” button. This will open the sprite editor window.

Up above to the left, there is a “Slice” button. Click on it to view the “Slice” options.

Select the type of slice. I know the Pixel Size of each frame (64 by 64)so I went with “Grid By Cell Size.”

Click on “Slice” to execute the slice.

We have sliced our sprite sheet into individual frames!

Animating

We can now animate our player. Drag the first frame of the sprite sheet into the hierarchy. Rename it.

Go to Windows > Animation > Animation. This will open up the Animation window. Drag the animation window into a panel if you’d like to have access to it in the future.

Select the Player game object. Press “Create” in the animation window.

Name and save the animation in the Animation folder. If you don’t have an Animation folder under your assets, create one.

We are now able to see the dope sheet. This is where we can animate game objects.

Since we want to animate the player walking down, we need to select all of the walking-down animations and drag them in the dope sheet.

Once in the dope sheet, we can select all keys and drag them apart to a sensible timing. As you can see, the sprite’s speed by default is fast. By dragging out the frames further in the timeline, we can adjust to a perfect speed.

The speed of the animation looks good now! This is the workflow of how to import, slice, and animate sprites in Unity!

We now have a walk-down animation for our player object! It’s ready to be implemented when holding down the input button for down.

Conclusion

This is more of a personal documentation post to memorize what I have learned so far in a course over at GameDevHQ. I have to admit that there are some things I have left out just for the sake of getting to the point. It’s stuff that I already know. So if you do try to follow along, and are stuck, let me know! I will get back to you with a solution!

Thank you for reading! :)

Hello everyone, My name is Gabriel Perez, I am a Unity Developer and a creator who is always learning and experimenting.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store