How To Import, Set Up, & Animate Your Sprites In Unity
Unity is an extremely powerful engine with a huge variety of capabilities. One of those features is the Animation System. This is a very simple and very easy-to-use tool that will allow you to take a sprite sheet and turn it into a full-fledged animation within seconds!
To start, you’ll need a sprite sheet or series of sprites that will be used for your animation.
Next, drag and drop your sprite sheets/assets into your Unity project. You will need to make some adjustments to the import settings on this sprite sheet but this isn’t hard.
- Set “Texture Type” to “Sprite (2D and UI)”
- If using a “Sprite Sheet” then change “Sprite Mode” to “Multiple” otherwise keep it as “Single”.
- Now change the “Pixels Per Unit” to whatever your sprites were created as. The standard is usually 300. This is also known as “Pixels Per Inch (PPI)” or “Dots Per Inch (DPI)”.
- Next, you will need to select a “Max Size”. This is dependant on what size of resolution your game will have but usually bigger is better since you can always scale down.
- Lastly, if you used a sprite sheet and set your “Sprite Mode” to “Multiple”, you will need to slice the sheet into individual sprites. To do this you will be using the ‘Sprite Editor”.
You may be prompted to download the 2D Sprites package which can be found in the “Package Manager”. This is fine and is needed in order to do this. Just follow the instructions and do it.
Now the sprite editor may look intimidating at first but trust me when I say it’s not.
To start, we will be clicking the button on the top of the menu labeled “Slice”. You should see a drop-down menu appear that looks like the example below.
Change the option “Type” to either:
- Grid By Cell Size
“Automatic” attempts to auto-slice out the individual sprites by detecting the empty space around them (Assuming there is any).
Now adjust the pixel size, offset, and padding settings as needed to box out your sprites and then hit “Slice”. You should now have a set of sprites in your project menu!
Now on to the Animation!
This is surprisingly the easiest part. Open up the “Animation” window which can be found under (Window>Animation>Animation).
- Now create an object to hold the animation. This can be an empty or a singular instance of one of your sprites.
- Click on this object within the hierarchy and click the “Create” button presented in the “Animation” window. Name and save the animation within your project.
- At the top left of the “Animation” window, you will see a red circular “Record” button. Click this button.
- Drag and drop the sprites that you are wanting to animate into the animation window. Make sure these are in the order that you want them to play.
- End the recording
- Now change the “Samples” setting within the “Animation” window to change the speed that your animation plays at and you're done!
The “Animator” window is used to transition between animations as well as to set parameters/variables that can be called on within your scripts and will determine things like whether an animation can play or not.
But I’ll have to go into that another time. Thanks for reading!