Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Black screen when switching from standard camera to Oculus Camera

Discussion in 'AR/VR (XR) Discussion' started by mrkittee, Apr 25, 2020.

  1. mrkittee


    Nov 13, 2019
    for my school project, I need to create an environment in Unity in which I can switch between the first person (therefore, the usual Main Camera) mode and the VR mode (OVRCameraRig).
    In order to achieve this, I set a new input called CKey assigned to 'c' and wrote a simple C# code to allow switching between the 2 modes: default is standard camera, pressing c switches to the VR camera, pressing it again will switch to standard camera and so on.
    For some reason tho, when I switch from the normal camera to the VR camera, I can only see a black screen.
    If I invert the order tho (meaning, VR as default first camera and standard as second) both cameras work just fine.
    I'm rather new to this stuff, so sorry if I'm just making a silly mistake.
    this is the code

    Code (CSharp):
    1. public class CambioCamera : MonoBehaviour
    2. {
    3.     public GameObject camFirstPerson;
    4.     public GameObject camVR;
    6.     void Start()
    7.     {
    8.         camFirstPerson.SetActive(true);
    9.         camVR.SetActive(false);
    10.     }
    12.     // Update is called once per frame
    13.     void Update()
    14.     {
    15.         if (Input.GetButtonDown("CKey"))
    16.         {
    17.             if (camFirstPerson.activeSelf)
    18.             {
    19.                 camFirstPerson.SetActive(false);
    20.                 camVR.SetActive(true);
    21.             }
    22.             else
    23.             {
    24.                 camFirstPerson.SetActive(true);
    25.                 camVR.SetActive(false);
    26.             }
    27.         }
    28.     }
    29. }