I have created the following script to take me to another scene on the press of a button.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ChangeScene : MonoBehaviour
{
public void changeToScene(int changeTheScene)
{
SceneManager.LoadScene(changeTheScene);
}
}
My app crashes when I navigate from a non-vr scene to a vr scene when I use this code. Is there something I need to be including within the script to stop the application from crashing?
I am using the headset demo scene from v1.0.0 of the gvr-unity-sdk as my VR scene. My non-VR is composed of a canvas with a button and gameobject to hold the above script.
I’ve looked through the documentation for a couple hours while using NurFACEGAMES tutorials to try to get a better handle on the subject, but I’ve come up with nothing so far. Any help is appreciated.
First time poster, apologies for any rules I may have broken in this question.
Fixed the problem by:
- Importing UnityEngine.VR; to a new script
- coded VRSettings.enabled = false; in start function when my first scene loads (currently trying to add the script to the unity splash screen, but that is a different question)
- Adding the script to a new game object on my first scene.
Hopefully this can eventually help someone in the future.
@nice-nate’s answer was correct but I think things have changed in more recent releases:
Appears you now have to include ‘None’ as an SDK options in your Player Settings > XRSettings.
Place it first in the list to start in non-VR.
Code to switch into VR is then:
// Call via `StartCoroutine(SwitchToVR())` from your code. Or, use
// `yield SwitchToVR()` if calling from inside another coroutine.
IEnumerator SwitchToVR() {
// 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[] DaydreamDevices = new string[] { "daydream", "cardboard" };
XRSettings.LoadDeviceByName(DaydreamDevices);
// Must wait one frame after calling `XRSettings.LoadDeviceByName()`.
yield return null;
// Now it's ok to enable VR mode.
XRSettings.enabled = true;
}