Lesson 92 +10 XP

Occlusion Culling

Occlusion Culling

Occlusion Culling prevents Unity from rendering GameObjects that are hidden behind other objects from the camera's perspective. This significantly reduces draw calls and improves performance in dense scenes.

How It Works

Without occlusion culling, Unity renders all objects within the camera's frustum, even those hidden behind walls. With occlusion culling:

  1. You bake occlusion data from your static scene geometry.
  2. At runtime, Unity uses this data to determine which objects are actually visible.
  3. Hidden objects are culled (skipped during rendering).

Setting Up Occlusion Culling

Step 1: Mark geometry as Occluder/Occludee Static Select each static GameObject and in the Inspector, use the Static dropdown to enable:

  • Occluder Static: This object can hide other objects (e.g., walls, terrain).
  • Occludee Static: This object can be hidden by occluders (e.g., furniture, props).

Step 2: Bake the occlusion data Open Window > Rendering > Occlusion Culling, then click Bake. Unity generates visibility data per camera region.

Step 3: Configure the Occlusion Area (optional) Add an Occlusion Area component to limit baking to specific regions, saving bake time and memory.

Occlusion Portals

An Occlusion Portal is a special component for openings like doors and windows. When closed, the portal blocks occlusion data, treating the door as opaque. When open, it allows objects behind it to be visible.

// Toggle a door portal at runtime
OcclusionPortal portal = doorObject.GetComponent<OcclusionPortal>();
portal.open = isDoorOpen;

Dynamic Objects

Occlusion culling only works automatically for static objects. Dynamic objects (enemies, players) are always tested against the pre-baked visibility data at runtime -- they do not block static objects but they themselves can be culled if fully hidden.

TL;DR

  • Occlusion Culling skips rendering of objects hidden behind other objects.
  • Mark geometry as Occluder/Occludee Static and then Bake from the Occlusion Culling window.
  • Use Occlusion Portals for doors and openings.
  • Dynamic objects are tested against baked data at runtime but do not contribute to occlusion themselves.