- Home /
Question by
pixelsharkcreations99 · Oct 12, 2020 at 09:03 PM ·
androidvrmobileil2cpp
Switching from 2D to VR Google Cardboard
I'm currently switching to VR mode on mobile (android, google cardboard) using this script
public void Switch()
{
StartCoroutine("SwitchToVR");
}
IEnumerator SwitchToVR()
{
// Device names are lowercase, as returned by `XRSettings.supportedDevices`.
string desiredDevice = "cardboard";
// Some VR Devices do not support reloading when already active, see
// https://docs.unity3d.com/ScriptReference/XR.XRSettings.LoadDeviceByName.html
if (String.Compare(XRSettings.loadedDeviceName, desiredDevice, true) != 0)
{
XRSettings.LoadDeviceByName(desiredDevice);
// Must wait one frame after calling `XRSettings.LoadDeviceByName()`.
yield return null;
}
// Now it's ok to enable VR mode.
XRGeneralSettings.Instance.Manager.InitializeLoader();
XRLoader xrLoader = XRGeneralSettings.Instance.Manager.activeLoader;
xrLoader.GetLoadedSubsystem<XRDisplaySubsystem>().Start();
//I'm pretty sure this is deprecated but like it's here anyways :)
XRSettings.enabled = true;
}
However when I try to switch to VR mode I get this error
AndroidPlayer(ADB@127.0.0.1:34999) NullReferenceException: Object reference not set to an instance of an object.
at EnableVR+<SwitchToVR>d__1.MoveNext () [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00000] in <00000000000000000000000000000000>:0
(Filename: currently not available on il2cpp Line: -1)
The line (Filename: currently not available on il2cpp Line: -1) to me suggests its an issue with il2cpp, if so it may be a Unity issue, however I thought I'd post here just in case I'm missing something.
Comment
Your answer
Follow this Question
Related Questions
What version of unity works with the Samsung Gear VR innovator edition for Note 4? 1 Answer
GearVR Recenters view when you take off and put on the headset 1 Answer
Is there a way to get URP working with Oculus Integration? 1 Answer
GoogleVR vs GearVR - frame dropping 0 Answers
Why would UI Layout be such a hog, and I don't even have any in my scene? CurvedUI! 0 Answers