Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

URP how to Change Camera Renderer at Runtime

Discussion in 'Scripting' started by DgoodingIndi, Aug 23, 2020.

  1. DgoodingIndi

    DgoodingIndi

    Joined:
    Feb 8, 2012
    Posts:
    41
    Last edited: Aug 23, 2020
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,756
    Hmm I don't see anything in the docs either. Maybe just have a preconfigured secondary camera as a prefab with the appropriate renderer.
     
  3. stastic

    stastic

    Joined:
    Jun 21, 2017
    Posts:
    1
    You can try setting the Renderer Index from UniversalAdditionaCameraData.
     

    Attached Files:

  4. DgoodingIndi

    DgoodingIndi

    Joined:
    Feb 8, 2012
    Posts:
    41

    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.

    Code (CSharp):
    1. UnityEngine.Rendering.Universal.UniversalAdditionalCameraData additionalCameraData = cam.transform.GetComponent<UnityEngine.Rendering.Universal.UniversalAdditionalCameraData>();
    2.        
    3. additionalCameraData.SetRenderer(newIndex);
    additionalCameraData.SetRenderer(newIndex);