Version: 2017.3 (switch to 2017.4)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

MonoBehaviour.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

Description

OnPreCull is called before a camera culls the scene.

Culling determines which objects are visible to the camera. OnPreCull is called just before this process.

This function is called only if the script is attached to the camera and is enabled.

If you want to change camera's viewing parameters (e.g. fieldOfView or just transform), this is the place to do it. Visibility of scene objects will be determined based on camera's parameters after OnPreCull.

#pragma strict
// Attach this to a camera.
// Inverts the view of the camera so everything rendered by it, is flipped
var cam: Camera;
function Start() {
	cam = GetComponent.<Camera>();
}
function OnPreCull() {
	cam.ResetWorldToCameraMatrix();
	cam.ResetProjectionMatrix();
	cam.projectionMatrix = cam.projectionMatrix * Matrix4x4.Scale(new Vector3(1, -1, 1));
}
function OnPreRender() {
	GL.invertCulling = true;
}
function OnPostRender() {
	GL.invertCulling = false;
}
// Attach this to a camera.
// Inverts the view of the camera so everything rendered by it, is flipped

using UnityEngine; using System.Collections;

public class ExampleClass : MonoBehaviour { Camera cam;

void Start() { cam = GetComponent<Camera>(); }

void OnPreCull() { cam.ResetWorldToCameraMatrix(); cam.ResetProjectionMatrix(); cam.projectionMatrix = cam.projectionMatrix * Matrix4x4.Scale(new Vector3(1, -1, 1)); }

void OnPreRender() { GL.invertCulling = true; }

void OnPostRender() { GL.invertCulling = false; } }

Did you find this page useful? Please give it a rating: