- Home /
How to toggle VR (cardboard) on and off in 5.6
I am having the biggest issue with VRsettings.enable(). All the info I find seem to take place before the 5.6 patch and nothing seems to be working the way it is suppose to. real simple I need the first scene to be non vr and the second to be VR. I have tried all combinations to try and get this to work. I will have VR enabled with cardboard selected in Player settings. On launch I will call
public IEnumerator startup()
{
VRSettings.LoadDeviceByName("none");
yield return null;
VRSettings.enabled = false;
}
which the splash screen will be vr (another problem ill deal with later) but the scene will load non-vr. but when I load a new scene, then on start on the new scene I call (newDevice = cardboard)
public IEnumerator LoadDevice(string newDevice)
{
VRSettings.LoadDeviceByName(newDevice);
yield return null;
VRSettings.enabled = true;
the scene will crash on android but work fine in editor. If i take out the Loaddevice stuff and just toggle VRSettings.enabled
it will work the first time I build it to the phone, but will crash every time there after. Am I missing something? or is there an issue with this? did it change in 5.6? I have no idea. any help would be greatly appreciated!
Answer by Liinnkk · May 23, 2017 at 11:03 PM
I answered a very similar question some days ago. There's some code you may find useful, so click here if you're insterested.
First, be aware that VR in Editor is just emulated by Google SDK, and VR in android is using Unity's Native Support, those are different things so the "if it works in editor it should work on android" logic will be not true. Keep it in mind.
If you want to start the game in Non-VR mode, configure your Player Settings like this: It's important to set 'None' as the first element in your SDKs list, this way your game will start and run in Non-VR mode (even the splash screen) until you start it manually.
To start the VR manually at run-time, you should load the VR device and set VRSettings.enable true when device is already loaded. This is really important because if you read the documentation of LoadDeviceByName(), you'll notice that this command (quoting the docs) "loads the requested device at the beginning of the next frame. So if you set VRSettings.enable true right after call LoadDeviceByName(), it will not load correctly.
But your code is not wrong! You should only be careful if you're calling it correctly. Considering the IEnumerator and the yield, the right way to call it will be using a Coroutine:
StartCoroutine(LoadDevice("cardboard"));
Hope it helps!
Oh! And one last thing: I strongly recommend you to download a newer version of Unity (try 2017.1 beta for now). That's because Unity 5.6 is using Google NDK 1.2, which has a known leak when you go in and out of VR.
awesome! the info you left at the last thread was exactly what I ended up using.
Can i ask something... What if i want just to set the VR$$anonymous$$odeEnabled = false in GVR? Because in my case, when it's load device to "cardboards" it's always back to true. So i can go to mono mode VR...
Im guessing you are asking how to do $$anonymous$$agic Window. you will want to have VRsettings.enable = true, and LoadDeviceByName(none). This will keep the VR motion but have no special viewing device and will work as a magic window.
thank you so much for this! I've been trying to figure out how to dynamically toggle Google VR (cardboard and daydream) along with standalone mode(mouse/keyboard input and/or touchscreen input) depending on which device is detected using Platform Dependent Compilation . I've had some obstacles with this since GVR likes to automatically start up components soemtimes even if you disable VR. For instance the reticle pointer still wants to instantiate even when I set LoadDeviceByName(none). Would it be better to disable all GVR objects by using tags? for instance, if I tag every gvr object with "GVR" then in my script set GameObject.FindObjectsWithTag("GVR").SetActive(false) ? What do you think is the best solution?
Your answer
Follow this Question
Related Questions
My VR game build crashes when the terrain is enabled. 0 Answers
VR game crashes 2 Answers
Access Violation Crash in Compiled VR game on projectile hit 1 Answer
Gear VR crash issue with unity 5.4.2 p2 0 Answers
Switching VR platforms via VRSettings 0 Answers