Version: 2021.1
LanguageEnglish
  • C#

Camera.onPreCull

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public static Camera.CameraCallback onPreCull;

Description

Delegate that you can use to execute custom code before a Camera culls the scene.

In the Built-in Render Pipeline, Unity calls onPreCull before performing the culling operation that determines what a Camera can see. To execute custom code at this point, create callbacks that match the signature of CameraCallback, and add them to this delegate. For example, you could change a Camera's settings to affect what the Camera sees.

For similar functionality that applies only to a single Camera and requires your script to be on the same GameObject, see MonoBehaviour.OnPreCull. For similar functionality in the Scriptable Render Pipeline, see RenderPipelineManager.

using UnityEngine;

public class CameraCallbackExample : MonoBehaviour { // Add your callback to the delegate's invocation list void Start() { Camera.onPreCull += OnPreCullCallback; }

// Unity calls the methods in this delegate's invocation list before rendering any camera void OnPreCullCallback(Camera cam) { Debug.Log("Camera callback: Camera name is " + cam.name);

// Unity calls this for every active Camera. // If you're only interested in a particular Camera, // check whether the Camera is the one you're interested in if (cam == Camera.main) { // Put your custom code here } }

// Remove your callback from the delegate's invocation list void OnDestroy() { Camera.onPreCull -= OnPreCullCallback; } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961