Question by 
               jroberts7 · Mar 14, 2018 at 02:21 PM · 
                unity 5vrscenescene-loadingscene-switching  
              
 
              Switching between a VR and non VR scene
I am trying to implement a button that switches from a nonvr scene to a vr scene. However i am getting spammed with an error Assertion failed: Assertion failed on expression: 'IsMatrixValid(matrix)' The code in scene 1:
 public void SwitchToVR()
     {
         
         SceneManager.LoadScene("VR");
     }
The code in scene 2:
  public void Awake()
     {
         StartCoroutine(ToggleDevice(true));
     }
 
  IEnumerator ToggleDevice(bool toggle)
     {
         XRSettings.LoadDeviceByName("OpenVR");
         yield return null;
         XRSettings.enabled = toggle;
     }
Could anyone provide assistance? Thanks
               Comment
              
 
               
              Answer by codemaker2015 · Oct 22, 2020 at 12:37 PM
  public void Awake() {
          StartCoroutine(SwitchToVR(()=>{
                Debug.Log("Switched to VR Mode");
          }));
  }
 
  IEnumerator SwitchToVR(Action callback) {
            // Device names are lowercase, as returned by `XRSettings.supportedDevices`.
            // Google original, makes you specify
            // string desiredDevice = "daydream"; // Or "cardboard".
            // XRSettings.LoadDeviceByName(desiredDevice);
            // this is slightly better;
            
            string[] Devices = new string[] { "daydream", "cardboard" };
             XRSettings.LoadDeviceByName(Devices);
      
            // Must wait one frame after calling `XRSettings.LoadDeviceByName()`.
            yield return null;
          
            // Now it's ok to enable VR mode.
            XRSettings.enabled = true;
            callback.Invoke();
   }
Your answer
 
 
             Follow this Question
Related Questions
Event when the scene is loaded 1 Answer
Laptop crashed; Unity scene 'broken' 0 Answers
Need a Script for Changing Scenes after pressing E to open locked door once a key has been found. 0 Answers
Loading a scene with script loads multiple copies of another scene, the crashes Unity 0 Answers
How do i create a scene variable? 3 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                