- Home /
enable & disable VR on mobile
Riffing off a question from @KristofferH
I have a mobile app and there is a button in the corner that I want to trigger a VR mode VRSettings.enabled
so you can put into cardboard (on IOs or Android)
in VR there is a button on the floor to go back to touchscreen mode
VRSettings.disabled
Doesn't work Does anyone have experience ?
Thanks
~be
Answer by SohailBukhari · Jun 23, 2017 at 08:39 AM
VRSettings.enabled Globally enables or disables VR for the application.
Set this to true to enable VR mode for the application. Note that this does not activate VR mode. VR mode is activated when a supported Head Mounted Display (HMD) is connected. The GearVR cannot be disabled once activated. A warning message is shown when attempting to disable a GearVR device.
Include using UnityEngine.VR;
at the top.
Call VRSettings.LoadDeviceByName("") with empty string followed by VRSettings.enabled = false; to disable VR in the start function to disable VR.
When you want to enable it later on, call VRSettings.LoadDeviceByName("deviceName") with the VR name followed by VRSettings.enabled = true;.
You should wait for a frame between each function call. That requires this to be done a corutine function.
Also, On some VR devices, you must go to Edit->Project Settings->Player and make sure that Virtual Reality Supported check-box is checked(true) before this will work. Then you can disable it in the Start function and enable it whenever you want.
Note:
This is known to work on some VR devices and not all VR devices. Although, it should work on Daydream VR. Complete code sample:
IEnumerator LoadDevice(string newDevice, bool enable)
{
VRSettings.LoadDeviceByName(newDevice);
yield return null;
VRSettings.enabled = enable;
}
void EnableVR()
{
StartCoroutine(LoadDevice("deviceName", true));
}
void DisableVR()
{
StartCoroutine(LoadDevice("", false));
}
According to Unity, it wont work in the Editor. It will work in Standalone builds.
Answer by FlaSh-G · Jun 23, 2017 at 07:52 AM
You can't just write
VRSettings.enabled
It's a variable that has a value that you can change. More specifically: To true or false. So your VR-enable code is
VRSettings.enabled = true;
and accordingly, disabling VR would be
VRSettings.enabled = false;
Your answer
Follow this Question
Related Questions
Please Help!!! Enable/Disable Script!!! 3 Answers
Help With Disabling/Enabling single GameObject 1 Answer
Toggling the light with lightmapping(baked and dynamic shadows) 1 Answer
Disabling first actor when switching to another camera. 0 Answers
Disabling/Enabling Different Character Controllers. 1 Answer