Unity Tips Performance : 2d Sprite Packer

Prasetio Nugroho
4 min readJan 24, 2019

--

Hello guys, great to see you. Now, we talk about performance in game. Sometimes we must be care about the performance. Because if your game performance good, it means that your game can be played with user or gamer smoothly.

Some game engines usually give some documentation or tips for optimize performance in game. It can optimize about graphic performance, cpu performace, RAM, or something else that can make your game better. In Unity game engine you can optimize your game. In this topic i will discuss about 2d Sprite which may effect in CPU usage or memory. But, first thing we should know about tweaking performance game in unity, you should use profiler in unity. What is Profiler?

Profiler window

Profiler is a tool from unity that helps you to optimize your game. It reports for you how much time is spent in the various areas of your game. For example, it can report the percentage of time spent rendering, animating or in your game logic. You can analyze the performance of the GPU, CPU, memory, rendering, and audio. You can access it from Window > Profiler. You can see the detail from the documentation here.

Let’s started with the package I already provided before. Here is the link for the package sprite packer sample. If you already import into unity, it contains two folder, Scene and sprite.

Scenes and Sprites folder

Each scene has same gameobject with different sprite. Here is the preview of hierarchy

Structure in hierarchy

Open first scene. Hit play button, and open the profiler window. Look at Rendering section Process. Under graphic section you can see SetPass Calls or Draw Calls. What is it mean?. I don’t know what exactly mean (LOL), but in unity documentation draw call means “To draw a GameObject on the screen, the engine has to issue a draw call to the graphics API (such as OpenGL or Direct3D). Draw calls are often resource-intensive, with the graphics API doing significant work for every draw call, causing performance overhead on the CPU side”. So, it is better with small draw call. You can see the draw call in first scene is 6.

Draw call in first scene

Open second scene and hit play, observe the profiler like scene one. And then compare the result of profiler from each scene.

Draw call in second scene

You can see the draw call in scene two is 3. Why their draw call different? because sprite setting in each scene different. For the second scene i use sprite packer and first scene don’t use special setting, just default setting. What is sprite packer?? It is a tool from unity that used for pack the graphic in an atlas or single texture (you can see manual here : Sprite Packer). But before use sprite packer, add tag for each sprite in import setting.

“icon_pack” tag in packing tag section

After tagging each sprite, click window -> sprite packer

Window -> Sprite Packer

Then sprite packer window will showed. Click pack, all sprite with the same tag will be in one single textrue or atlas.

Packing all sprite with the same tag in single texture

For conclusion, you can use sprite packer to reduce draw call. Like unity manual said “For optimal performance, it is best to pack graphics from several sprite textures tightly together within a single texture known as an atlas.”

--

--

Prasetio Nugroho
Prasetio Nugroho

Written by Prasetio Nugroho

Interested in new tech, gaming, programming and another knowledge or possibilites that can make me better. Cheers!!

No responses yet