Collision Matrix: Listen to the cry of CPU!

While game object selected in hierarchy, on the Inspector window we have 2 very important things on the top tag and layer in this time we will hang out with layer and its Collision Matrix to optimize our CPU.

This post ease down the blog post of unity best practices to lay man solely.

All game objects in the start are on default layer hence all can collide to others. For few object it seems not an problem but for if we have to deal with many such cases it may put down load on CPU on mobiles. Here comes the layer collision matrix that is responsible for defining interactions between layers.

Let me first summarize you about the result of unity blog post about this technique effectiveness. He explains that only check those layers that can interact each other or will be related in game.
I would like to thank Ricardo Aguiar for his fabulous guide about it. He highlights example of 2000 game objects where 1000 green and red cubes respectively for experiment. Here is assumption, that only same color cubes are allowed to collide each other so he tried to collision first with default layers and using code condition then another experiment with separate layer for both classes(red, green) as you can see in above figure.

Here are conclusions, by the separate layer experiment you can significantly see the difference in no. of collisions and CPU can have better breath though.

According to it, there’s quite a difference on the amount of CPU spent on physics, as we can see from the profiler data, from using a single layer ( avg ~27.7 ms ) to separate layers ( avg ~17.6ms ).

You can try experiment by your own with it just simply create scripts for collision detection like below and only add condition for first experiment.

Have a nice time.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow by Email