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.
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.
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.
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“>
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!
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.
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.
On mobile, don’t go nuts with the lightmap’s Atlas Size either because it’ll eat up your texture RAM pretty fast.
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.
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 site of the model
Back side (will never be seen by the player)
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.
More detailed information on Occlusion culling can be found on Unity’s website.
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.
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:
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!