# OnWillRenderObject()

> Called for each camera if the object is visible and not a UI element.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.6/script-reference/unityengine.md)

```csharp
public void OnWillRenderObject()
```

### Remarks

`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: - Per-camera material or shader adjustments, for example setting shader keywords or per-camera uniforms. - Per-camera logic that doesn't affect the object's transform or visibility. - Custom rendering logic, like setting up camera-dependent effects. `OnWillRenderObject` is not appropriate for: - Modifying the object's position or transform. This is because the culling process (which decides if an object is visible) has already occurred. If you move the object here, it may already be included in the render list for this frame, and the scene may not update as expected. You could see visual artifacts, popping, or inconsistent rendering results. - Changing the camera. You can read from [Camera.current](/engine/6000.6/script-reference/unityengine/camera/current.md), but changing camera settings here is generally not recommended. If you need to change camera settings before culling, use [MonoBehaviour.OnPreCull()](/engine/6000.6/script-reference/unityengine/monobehaviour/onprecull.md) or [MonoBehaviour.OnPreRender()](/engine/6000.6/script-reference/unityengine/monobehaviour/onprerender.md) instead. [Camera.current](/engine/6000.6/script-reference/unityengine/camera/current.md) 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()](/engine/6000.6/script-reference/unityengine/monobehaviour/onprecull.md) or [MonoBehaviour.OnPreRender()](/engine/6000.6/script-reference/unityengine/monobehaviour/onprerender.md)

### Examples

```csharp

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);
        }
    }
}
```
