Camera.current returns null when calling it in OnWillRenderObject with UniversalRP

Hi,

I have some inconveniences because in UniversalRP, Camera.current returns null when calling it in OnWillRenderObject.

I hope Unity supports this.

I’ve sent the bug report to Unity and the response says “the issue is not a bug but rather a known limitation of the current implementation of this functionality”.
I want to create mirror reflection system. However I can’t render the results per camera because of this limitation.

In OnWillRenderObject’s document, It is said “Note that Camera.current will be set to the camera that will render the object.”.
There is the error in the document about OnWillRenderObject.

Thanks

This does look like a bug/docs omission to me, specially when OnWillRenderObject is listed as fully supported for URP:
https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@7.1/manual/universalrp-builtin-feature-comparison.html

1 Like

any update on this?

2021: Any update on this?

OnWillRenderObject is impossible in modern rendering architecture, so it’s never appear in srp.

Strange that the documentation says this, all the MonoBehaviour OnXXX function won’t work in a SRP. Documentation isn’t exactly a strongpoint when it comes to SRP, so it likely just hasn’t been updated?

Alternatively, you can validate if the bounds of the object you want to check is within a certain camera’s frustrum to the same effect:

private static Plane[] frustrumPlanes = new Plane[6];
      
private static bool IsVisible(Camera camera, Bounds bounds)
{
     GeometryUtility.CalculateFrustumPlanes(camera.projectionMatrix, frustrumPlanes);

     return GeometryUtility.TestPlanesAABB(frustrumPlanes, bounds);
}

Any Renderer has a bounds property you can use.

1 Like

Your sample code takes a camera as input - that’s exactly what we don’t have in the OnWillRender callback due to this bug.

@BattleAngelAlitar Not sure what you are referring to - the callback does happen in SRP, it’s just not populating the Camera.current field.

You can use the SRP beginCameraRendering event to get the current camera that’s rendering, then you can use @StaggartCreations function.

Feel free to check **this link **for beginCameraRendering event documentation

1 Like