Optimizing Graphics Performance
Making your game run smoothly is of prime importance to its success. Thankfully Unity is there for you! We have spent a lot of time and energy making it run fast on a wide variety of hardware. Below are some simple guidelines to maximizing the speed of your game.
In summary - combine, combine, combine
- If you care about performance, combine meshes.
- If you care about performance, make sure all your combined meshes also share the same material and texture.
- Profiler and Rendering Statistics window are very helpful!
In detail:
Modern graphics cards are really good at pushing a lot of polygons, but they have quite a bit of overhead for every batch that you submit to the graphics card. So if you have a 100-triangle object it is going to be just as expensive to render as a 1500-triangle object. The sweet spot for optimal rendering performance is somewhere around 1500-4000 triangles per mesh.
You only pay a rendering cost for objects that have a Mesh Renderer attached. And you only pay for those that are within the view frustum. There is no rendering cost from having a lot of empty GameObjects in your scene.
- The best way to improve rendering performance is to combine objects together so each mesh has around 1500 or more triangles and uses only one Material for the entire mesh.
It is important to understand that just combining two objects which don't share a material does not give you any performance increase at all. If you want to combine effectively, you need to make sure your mesh uses only one material after you have combined it.
There is one thing to be aware of when combining objects though: if you use a lot of small lights in your scene, it might make sense to combine only objects that are close to each other.
The rendering cost for a mesh that has multiple materials is the same as having multiple renderers for each material. The most common reason why you have multiple materials is because two meshes don't share the same textures. So, if you want to optimize rendering performance, you need to make sure that the objects you combine share textures.
- Unity is very good at pushing lots of polygons. Unity uploads all geometry to the graphics card for good cache utilization and optimal data alignment.
- You simply have to make sure that the graphics card doesn't have to handle large numbers of batches.
- The number of Pixel Lights affecting an object heavily affects performance.
If you want to have the best performance and don't care about Bumpmapping or Pixel Lighting, go to and set Pixel Light Count to zero. This will simply use vertex lighting for all objects. This means all geometry will be rendered only once per frame. This is an extremely useful LOD setting, so your game can run fine on older graphics cards.
Pixel lights
If you use pixel lighting, then each GameObject has to be rendered as many times as there are pixel lights that affect the object. If you combine two objects that are very far apart, it might increase the size of the object and now you have a lot of lights affecting this big object. If your objects were separate however, the light wouldn't have to be applied on the part of the mesh which is far away. This can result in rendering the combined mesh as many times as the uncombined mesh thus you didn't save anything. For this reason, you should keep GameObjects that are very far away as individual Meshes.
When rendering a mesh, Unity finds all lights surrounding the mesh. It then figures out what lights affect the mesh the most. The are used to modify how many of the lights end up as pixel lights and how many as vertex lights.
Every light calculates its importance based on how far away it is from the mesh and how intense it is.
Some lights are more important than others depending on the game context. For this reason, every light has a Render Mode setting which can be set to Force Pixel or Force Vertex.
Imagine the player's car with head lights driving through the night. The head light is the most important light in the game. For this reason, the head lights Render Mode should be set to Force Pixel.
If you have a light that isn't very important and also visually doesn't gain much from being a pixel light, set the lights Render Mode to "Force Vertex". This way you don't waste rendering performance or lose any visual quality.
Per-layer cull distances
You might want to cull small objects earlier to reduce number of draw calls. For example, small rocks and debris could be made invisible at much smaller distance than large buildings. To do that, put small objects into a separate layer and setup per-layer cull distances using Camera.layerCullDistances script function.
Shadows
Shadows are generally expensive. They can add a lot of performance overhead to your game if they are not used correctly. For more details about shadows, please read the Shadows page.
