URP how to Change Camera Renderer at Runtime

I have been tried checking the documentation, and have tried a few searches on forums, and am not seeing any solution.

https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@7.4/api/UnityEngine.Rendering.Universal.CameraData.html

Edit:
Also I am aware that I can change the default renderer, however I need a secondary camera to have a different Renderer.

Hmm I don’t see anything in the docs either. Maybe just have a preconfigured secondary camera as a prefab with the appropriate renderer.

You can try setting the Renderer Index from UniversalAdditionaCameraData.

3 Likes

This solved it.
Thank you. I had been trying to change “UnityEngine.Rendering.Universal.CameraData” , and didn’t think about the Additional Camera Data Script.

UnityEngine.Rendering.Universal.UniversalAdditionalCameraData additionalCameraData = cam.transform.GetComponent<UnityEngine.Rendering.Universal.UniversalAdditionalCameraData>();
       
additionalCameraData.SetRenderer(newIndex);

additionalCameraData.SetRenderer(newIndex);

5 Likes