How to disable VR on Unity Splash Screen while Google Cardboard is enabled
Question in title. Currently I am fooling with the following code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.VR;
public class StartVRDisabled: MonoBehaviour {
[RuntimeInitializeOnLoadMethod]
static void OnRuntimeMethodLoad()
{
VRSettings.enabled = false;
}
}
I am really unsure of how to apply script to the splash screen, or apply script which works during the initialization of the app.
Any help is appreciated.
Still need help on this. From looking around online it seems that Unity Personal has no custom scripting capabilities. Will continue searching.
Answer by Liinnkk · May 16, 2017 at 07:08 PM
The only way I found to disable VR in splash screen is to start the game in a non-VR mode and then change it to Cardboard (or any other VR device) at runtime. According to VR Overview documentation you can do it setting the "None" VR SDK as your first SDK of the Supported VR SDK list and through the VRSettings.LoadDeviceByName() command. Here's the quote:
Including None as a device in the list allows you to default to a non-VR application before attempting a VR device’s initialization. If you place None at the top of the list, the application starts with VR disabled. Then, you can then enable and disable VR devices that are present in your list through script using VRSettings.LoadDeviceByName.
The setup should look like this:
Since the VRSettings.LoadDeviceByName() loads the requested device at the beginning of the next frame, you should call VRSettings.Enable() in the next frame, as soon as device is loaded. You can use this example code available on the command documentation.
// Run in split-screen mode
using System.Collections;
using UnityEngine;
using UnityEngine.VR;
public class RuntimeCardboardLoader : MonoBehaviour
{
void Start()
{
StartCoroutine(LoadDevice("cardboard"));
}
IEnumerator LoadDevice(string newDevice)
{
VRSettings.LoadDeviceByName(newDevice);
yield return null;
VRSettings.enabled = true;
}
}
Assign this script to a GameObject called CardboardLoader or something like this and put your CardboardLoader in the first scene after the Splash Screen. It should work.
Warning: As stated in this thread there's a leak problem on Google NDK 1.2, which is used by Unity 5.6 when you go in and out of VR. So if you're using Unity 5.6 and want to use the LoadDeviceByName() method, upgrade your Unity to a newer version (in this moment, Unity 2017.1.0b5).
Your answer
Follow this Question
Related Questions
Google Cardboard App not being 360 1 Answer
Unity to iOS VR (via Google Cardboard) - screen is squashed 0 Answers
GoogleVR / C# - How to, with the "pointer click": click 1 move a cube and click 2 move back the cube 0 Answers
How do I move forward & raycast based on the MainCamera direction (in UFPS) 0 Answers
Google Cardboard VR + GazeInputModule - Get trigger events when not over UI 1 Answer