parallax background

Hello everybody.

Today I wanna talk about some things we found out about performance tweaking in Unity.
There are a lot of good resources on the internet about performance optimization you can look up.

In this article, tough, I will focus on things that really helped us to run the game even on old devices while keeping a good level of graphic quality. I will try to keep it as simple as possible and easy to understand without going into too much confusing technical details.
So let’s get straight to the point.

1. Draw Calls

Draw Calls can have quite a huge impact on the performance of a game – especially on mobile devices.
Let’s keep it simple: Every object that has it’s own material assigned to it uses a draw call.  There are a couple of other things that produce draw calls (like shadows or lightmaps) but let’s put that aside for now.

Mark objects as static if possible

Thankfully Unity got a couple of tricks up it’s sleeve to reduce draw calls by batching!
Unity’s Dynamic Batching happens under the hood and we don’t have to set it up manually.
Static Batching, on the other hand, requires objects to be marked as static in the inspector window. So, basically, if you have any objects in your game that won’t move, resize or rotate mark them as static. 

Bildschirmfoto 2015-09-25 um 21.59.19

Combine textures into one texture atlas

Since every material uses a draw call you should reduce the number of materials you’re using in your game.
Sounds simple, right? Well, it actually is with a Texture Atlas.
A UV-map of a model tells the shader where the object’s polygons are located on a texture image.
If you only use a fraction of a full-size image for your object’s UV-map, you can fit more UV-maps from different objects on one image.

<a href="http://www.bitsalive.com/wp-content/uploads/2015/09/RunAreaObjects_diffuse go to these guys.jpg“>RunAreaObjects_diffuse

This image contains textures of 6 different models

As a result, you have one material rendering multiple objects in your scene simultaneously using one draw call because of Unity’s Dynamic Batching. Neat!

2. Lightmaps

Lightmaps are used to bake the light information of your scene into images. This saves a lot of computation time since shadows and light behavior don’t need to be rendered in realtime.
Obviously this only works with objects and lights that are static and won’t change their position during the game.
There’s a lot of information on how to bake lightmaps in Unity available on the internet.  Check out this great tutorial or this article on the Unity website.

Let’s talk about what lightmap baking can and cannot do.

The good

A lightmapped scene can increases the game’s performance a lot.
Additionally you can use a more complex light setup to create the atmospheric mood. Baked lights don’t need to be rendered in realtime so basically you can use as many as you want.

There are a couple of things you should keep in mind though.

Make sure you scale down non-important objects in your lightmap. If you leave every object at a scale of 1 you end up with a lot lightmaps which has an impact on the game’s performance because it increases draw calls and needs more texture memory.
You can set the scale by selecting a mesh renderer in the Hierarchy and go to Object in your Lighting inspector window.
There you can change the parameter Scale in Lightmap.

Bildschirmfoto 2015-09-25 um 22.26.05

On mobile, don’t go nuts with the lightmap’s Atlas Size either because it’ll eat up your texture RAM pretty fast.

The bad

Baked lighting can only be used for static objects and lights.
It uses more texture RAM than realtime rendering and creates additional draw calls.

One big downside of lightmaps is that Normal maps won’t work with baked objects with Unity 5’s new Enlighten engine.
You can try to fool around with the Directional Mode setting in the Lightmap inspector, but this may decrease your game’s performance and isn’t recommended for mobile devices.
They probably will fix this in the future, but for now – no Normal maps on baked objects.

3. Polycount

Try to keep the polycount low for your models.
You can get away with a low polycount by using Normal maps to add details onto your mesh (if you don’t bake lightmaps for them).

Additionally you can use Unity’s LOD system to have a more detailed object when the player is close and switch to a low poly version when he’s farther away.

In our Ski Flying WC 2016 game, the player can’t walk around freely. Therefore we were able to delete a lot of polygon from the backside of the objects, since they’ll never be seen by the player.

front

Front site of the model

back

Back side (will never be seen by the player)

4. Occlusion Culling

Occlusion Culling removes models in runtime when they are out of sight of the camera so they will be ignored by the renderer.
You can find Unity’s occlusion culling system under Window → Occlusion Culling.

Bildschirmfoto 2015-09-25 um 23.06.46

More detailed information on Occlusion culling can be found on Unity’s website.

5. Texture resolution

If possible, reduce the size of your textures. I know… lots of 2048 textures look great in your game but they eat a lot of memory as well.
This is particularly import for mobile games.
You can set the image resolution in the import settings of the texture. You’ll need to set the Texture Type to Advanced to access to the Max Size parameter.

Bildschirmfoto 2015-09-25 um 23.16.08

Summary

Tweaking the performance differs from game to game. The best is to play around with the settings and see with how much you can away before the game starts to look bad.
Most of these things are important for mobile games. A decent PC can handle a lot more than a mobile phone.
Let’s sum this up:

  • mark static, non-moving object as static
  • use a Texture Atlases to reduce the number of materials
  • bake lightmaps for static objects and lights
  • reduce the lightmap scale for non-important objects
  • keep your polycount low and remove polygons that will never be seen by the player
  • use LOD if necessary
  • use Unity’s occlusion culling to remove hidden objects from the rendering pipeline
  • reduce the image resolution for your textures (unless you use a virtual texturing system like the amazing Amplify Texture)

I hope you found some useful tips and tricks in this article and we were able to help you boosting your game’s performance!
If you got any questions drop a comment below or get in touch on Twitter.

Thanks for reading!

Ronald Soelkner
Ronald Soelkner
Game Designer at BitsAlive - Follow us on Twitter: @bitsalive

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.

'