3 Steps to Better Performance


3 Steps to Better Performance

Hello, I am Florian game programmer at our student project “Project Grappling Fight”. Today I want to show you our approaches to handling performance problems during project development. The analysis by the unity tool showed that the draw calls take too long. In this guide I would like to present you our 3 solutions to get the problem under control.

The Obvious Way

The easiest and fastest way to reduce the draw calls was to reduce the render distance. The clipping plane was hidden using a simple post processing fog in unity. This way might not be applicable for every game, but for us it fits into the setting and brought us a little more performance.

Clipping Plane

The Hard Way

A somewhat complicated way to optimize the performance is batching. Unity differentiates between static batching and dynamic batching.

Static Batching

Static batching combines meshes in different ways, which do not change or move and tries to reduce the draw calls. It does not reduce the number of draw calls exactly but tries to reduce the render state changes. For static batching the game object must fulfill some properties. It is active, it has a mesh filter, a mesh, the mesh is read write enabled, it must have at least one vertex and it has not already been combined with a mesh. To enable static batching, it must be enabled in the player settings under other settings. In the scene view, static batching can now be activated for the respective game object.


Dynamic Batching

Dynamic batching combines moving meshes at runtime. All vertices in world space are transformed on the CPU. Therefore, it only provides an advantage if the transformation takes less time than a draw call. Generally, there is no formula to determine if it makes a difference. Usually, it should be compared with the unity analysis functionalities to see if dynamic batching provides a benefit.  To use dynamic batching, it must be enabled in the player settings under other. Dynamic batching has some limitations that must be considered to have an effect. Meshes can only have under 900 vertex attributes and under 300 vertices. Game objects must have the same material and game objects must use the same lightmap.

The Holy Grail

A problem in our project was that our platforms had too many singles meshes. These many individuals meshes had no advantage for us and so it was the goal to combine these meshes. Since we are not artists, the meshes were combined using code. Unity offers a simple way to do this using the mesh.combine meshes function, which combines the meshes into one mesh. This way was chosen, and the performance was increased a lot. However, the function needed some time to run, and the loading time of our game increased significantly. The further conclusion was to merge the meshes before runtime and to save them again. This would also be relatively easy to code, but there is already a practical asset in unity that does this work for you. Mesh Combiner Asset

Meshes

Conclusion

Performance is always an issue in game development. We made the mistake of ignoring the problem for a long time and not optimizing right away. Generally, there are many approaches to solving the problem, but it takes a lot of time and should be implemented from the beginning. 

Sources

Fog

Batching

Static Batching

Dynamic Batching

Combine Mesh

Good Practices FPS Optimization

Get Project Grappling Fight

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.