Version: 2021.1
Occlusion Areas
The Occlusion Culling window

Occlusion Portals

Switch to Scripting

An Occlusion Portal can either be open or closed. When an Occlusion Portal is closed, it occludes other GameObjectsThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary
. When an Occlusion Portal is open, it does not occlude other GameObjects.

If you have a GameObject in your SceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary
that has an open and a closed state (such as a door), you can create an Occlusion Portal that represents it in the occlusion cullingA that disables rendering of objects when they are not currently seen by the camera because they are obscured (occluded) by other objects. More info
See in Glossary
system. You can then set the open state of the Occlusion Portal according to the state of that GameObject. An Occlusion Portal component does not need to be placed on the GameObject it represents.

Setting up an Occlusion Portal in your Scene

  1. Choose a suitable GameObject in your Scene to act as an Occlusion Portal. Good candidates for Occlusion Portals are medium to large solid GameObjects, such as a door.
  2. Ensure that the GameObject is not marked as Occluder Static or Occludee Static.
  3. Add an Occlusion Portal component to the GameObject.
  4. Bake the occlusion data for your Scene. See Getting started with occlusion culling for instructions.
  5. Ensure that the Occlusion Culling window, the InspectorA Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info
    See in Glossary
    panel and the Scene viewAn interactive view into the world you are creating. You use the Scene View to select and position scenery, characters, cameras, lights, and all other types of Game Object. More info
    See in Glossary
    are all visible.
  6. In the Scene view, move the CameraA component which creates an image of a particular viewpoint in your scene. The output is either drawn to the screen or captured as a texture. More info
    See in Glossary
    to a position where it is directly in front of the Occlusion Portal.
  7. Select the GameObject with the Occlusion Portal component.
  8. In the Inspector window, toggle the Occlusion Portal component’s Open property on and off. In the Scene view, observe the difference in occlusion culling.

Opening and closing an Occlusion Portal at runtime

Use a script to set the Occlusion Portal’s open property to the desired state.

void OpenDoor() {
     // Toggle the Occlusion Portal's open state, so that Unity renders the GameObjects behind it
    myOcclusionPortal.open = true;
    
    // Call a function that plays a door opening animation, or otherwise hides the GameObject
    …
}

Occlusion Portal component reference

Property: Function:
Open If enabled, the Occlusion Portal is open, and does not occlude Renderers. If disabled, the Occlusion Portal is closed, and occludes Renderers.
Center Set the center of the Occlusion Portal. The default value is 0,0,0.
Size Define the size of the Occlusion Portal.
Occlusion Areas
The Occlusion Culling window
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961