Called for each camera if the object is visible and not a UI element.
OnWillRenderObject
is called after culling has determined that the object will be rendered, but before the object is rendered by each camera. It's called once per camera that will render the object, for every visible, non-UI object with this MonoBehaviour.OnWillRenderObject
is called multiple times per frame. It's not called on disabled MonoBehaviours.OnWillRenderObject
is appropriate for:
OnWillRenderObject
is not appropriate for:
Camera.current will be set to the camera that will render the object.
Note: OnWillRenderObject
has no effect when called from a UI element.
Additional resources: MonoBehaviour.OnPreCull or MonoBehaviour.OnPreRender
using UnityEngine; using System.Collections;
public class ExampleScript : MonoBehaviour { public Renderer rend;
private float timePass = 0.0f;
void Start() { rend = GetComponent<Renderer>(); }
void OnWillRenderObject() { timePass += Time.deltaTime;
if (timePass > 1.0f) { timePass = 0.0f; print(gameObject.name + " is being rendered by " + Camera.current.name + " at " + Time.time); } } }