Oh Boy, This is Starting to Feel Like a Real Game — Importing Sprite Sheets for Animation in Unity
It hasn’t been that long since I started working on my top-down shooter. I already have my player reacting to user input and some enemies spawning intermittently. I can shoot them down and be destroyed by colliding with them. This project is starting to feel like a real game!
The new sprites are making a big difference in the look and feel of my game. In this quick walkthrough, I would like to take a moment to outline how to import new sprites and sprite sheets into your project and convert them to GameObjects ready for animation.
You can import a new asset into your project in one of three ways:
- On the menu bar, you can select Assets, Import New Asset. A file explorer window will open. You can navigate to the assets you wish to include and click on the import button.
- You can right-click in the Assets window of your Editor. From the context menu, you can then select Import New Asset. A file explorer window will open. You can navigate to the assets you wish to include and click on the import button.
- You can navigate to the files you wish to import and drag them directly into your desired folder in the Assets window.
IMPORTING SPRITE SHEETS
Importing a sprite sheet can be done in the same way as described above. One big difference is that we have to tell Unity how to interpret this image file. The main concern is to make sure Unity understands that this image contains two or more sprites inside of it. We call this process slicing.
To slice a sprite sheet, start by selecting it in your Assets. The Inspector will now show the import settings for the selected image. The following items are of particular interest to us in this case.
- Sprite Mode may be the most important setting for a sprite sheet. Make sure to change it from single to multiple.
- Pixels Per Unit determine how many pixels will represent one unit. Change this value to reflect the resolution of your sprites.
- When using Pixel art, change the Filter Mode to Point(no filter). For all other styles, the default value will work well.
- When using Pixel art, change the Compression to None. For all other styles, the default value will work well.
Having pressed the Apply button, we can now begin to slice our sprite sheet by clicking on Sprite Editor.
Note: If you have not yet installed the 2D sprite package, Unity will prompt you to do so.
A new Editor window will open. In this window, we can select the method that Unity will use to slice our image.
The process for slicing is the following:
- Click on the Slice button on the top left.
- The slicing method is set to Automatic by default. Click on the drop-down menu to select Grid By Cell Size. This option is good if you know the size of your sprites. Alternatively, you can choose By Cell Count to slice the image based on rows and columns.
- The pivot represents the point in space the sprites will be on. This point will also be the center from which you can rotate and scale your game sprites.
- To confirm your settings, click on the Slice button.
- Finally, to complete the operation, click on the Apply button on the top right.
By following these steps, your assets will now be ready to use in your game. You will be able to use each slice as an individual sprite. More importantly, this process will allow you to set up your assets to begin creating animations.
I will cover the topic of animating sprites in my next article.