How to navigate from a non-VR scene to a VR enabled scene within Android
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.
So I am pursuing the possibility that the GvrViewer.Instance.VR$$anonymous$$odeEnabled has something to do with my ability to launch the next scene.
$$anonymous$$y issue now is that I am receiving an error which says no GvrViewer Instance has been found. This makes sense because the scene I am on is non-VR therefore there is no viewer.
I am now trying to get the script to reference the GvrViewer in the VR scene before setting VR$$anonymous$$odeEnabled to true.
Answer by nice-nate · Apr 07, 2017 at 03:41 AM
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.
Answer by jeromeWork · Feb 07, 2018 at 11:13 AM
@nice-nate's answer was correct but I think things have changed in more recent releases: https://developers.google.com/vr/develop/unity/guides/hybrid-apps
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;
}
Your answer
Follow this Question
Related Questions
Save and load scene from file 2 Answers
Switching between a VR and non VR scene 1 Answer
Keeping track of the previous scene 1 Answer
Loading and Unloading scenes 2 Answers