Why Occlusion Culling Improves Performance in Unity
Objective: To explain what Occlusion Culling is and why it can be beneficial to improving the performance of your project in Unity.
Occlusion culling is very important for optimising your scenes as it prevents Unity from making rendering calculations for game objects that are hidden from view (occluded) in the scene. There is potential for Unity to waste CPU and GPU time on rendering these, and this is where occlusion culling steps in.
Occlusion culling only works on elements that are static or the tags that have been switched for dynamic elements to be viewed as static.
Let’s now set the tag of some of our game objects in our scene — Walls, floors, ceilings, columns etc.
How to Set the Tags
Firstly we need to have the game objects highlighted in the Hierarchy, then we are going to head over to the Inspector and click on the drop-down box ‘Static’. From here we are going to switch on ‘Occluder Static’ and ‘Occludee Static’:
Then under the ‘Occlusion’ tab we are going to hit ‘Bake’:
Then on the ‘Occlusion Culling’ box in the Scene window, let’s switch this to ‘Visualize’:
From here, let’s move our camera around so we can see that it now only renders what is visible to the camera: