
I can’t see an option to upgrade XR plugin management.

I can’t see an option to upgrade XR plugin management.
my errors:
Initializing XR Failed.
UnityEngine.Debug:LogError(Object)
d__2:MoveNext() (at Assets/MyStuff/Scripts/VRToggle.cs:33)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
when i enter VR
using System.Collections;
using UnityEngine;
using UnityEngine.XR.Management;
public class VRToggle : MonoBehaviour
{
public bool vrOn;
public void Start()
{
if (vrOn)
{
StartCoroutine(VRStart());
}
else
{
VRStop();
}
}
private IEnumerator VRStart()
{
Debug.Log("Initializing XR...");
if (!XRGeneralSettings.Instance.Manager.isInitializationComplete) yield return XRGeneralSettings.Instance.Manager.InitializeLoader();
yield return 0;
if (XRGeneralSettings.Instance.Manager.activeLoader == null)
{
Debug.LogError("Initializing XR Failed.");
}
else
{
Debug.Log("Starting XR...");
XRGeneralSettings.Instance.Manager.StartSubsystems();
}
}
//public IEnumerator VRStart()
// {
//Debug.Log("start vr");
//var xrManager = XRGeneralSettings.Instance.Manager;
//if (!xrManager.isInitializationComplete)
//{
// yield return xrManager.InitializeLoader();
// xrManager.StartSubsystems();
// Screen.sleepTimeout = SleepTimeout.NeverSleep;
//}
private void VRStop()
{
Debug.Log("Stopping XR...");
if (XRGeneralSettings.Instance != null) XRGeneralSettings.Instance.Manager.StopSubsystems();
Camera.main.ResetAspect();
}
//{
//Debug.Log("stopping vr");
//var xrManager = XRGeneralSettings.Instance.Manager;
//if (xrManager.isInitializationComplete)
//{
// xrManager.StopSubsystems();
// xrManager.DeinitializeLoader();
// //cam.ResetAspect();
// //cam.fieldOfView = defaultFov;
// //cam.ResetProjectionMatrix();
// //cam.ResetWorldToCameraMatrix();
// Screen.sleepTimeout = SleepTimeout.SystemSetting;
//}
//}
}
Hi, try this on line 27-28:
Debug.Log("Initializing XR...");
yield return XRGeneralSettings.Instance.Manager.InitializeLoader();
And check "Cardboard XR Plugin, and uncheck “Initialize XR on Startup” in Project Settings/XR-Plug-in Management.
if i print that XRGeneralSettings.Instance.Manager.activeLoader, its
“XR Loader (Google.XR.Cardboard.XRLoader)”
yours seems to be null since it goes there.
also this script actually looks the same:
https://docs.unity3d.com/Packages/com.unity.xr.management@3.2/manual/EndUser.html
thanks - so it looks like this:
Debug.Log("Initializing XR...");
/*if (!XRGeneralSettings.Instance.Manager.isInitializationComplete)*/ yield return XRGeneralSettings.Instance.Manager.InitializeLoader();
yield return 0;
(box unchecked on startup)
I am also tring to use this code from the documentation
Coroutine VRStart()
{
return StartCoroutine(startVRRoutine());
IEnumerator startVRRoutine()
{
// Add error handlers for both Instance and Manager
var xrManager = XRGeneralSettings.Instance.Manager;
if (!xrManager.isInitializationComplete)
yield return xrManager.InitializeLoader();
if (xrManager.activeLoader != null)
xrManager.StartSubsystems();
// Add else with error handling
}
}
but how do i get the code to run? I thought you called ienumerators not coroutines?
thanks
and you have cardboard checked?
I also tried the code that mgear posted adding in a bool to determine which function to run:
using System.Collections;
using UnityEngine;
using UnityEngine.XR.Management;
public class startXR : MonoBehaviour
{
public bool xrStart;
public void Start()
{
if (xrStart)
{
StartCoroutine(StartXR());
}
else
{
StopXR();
}
}
public IEnumerator StartXR()
{
Debug.Log("Initializing XR...");
yield return XRGeneralSettings.Instance.Manager.InitializeLoader();
if (XRGeneralSettings.Instance.Manager.activeLoader == null)
{
Debug.LogError("Initializing XR Failed. Check Editor or Player log for details.");
}
else
{
Debug.Log("Starting XR...");
XRGeneralSettings.Instance.Manager.StartSubsystems();
}
}
void StopXR()
{
Debug.Log("Stopping XR...");
XRGeneralSettings.Instance.Manager.StopSubsystems();
XRGeneralSettings.Instance.Manager.DeinitializeLoader();
Debug.Log("XR stopped completely.");
}
}
I think this is the full error log entry:
using System.Collections;
using UnityEngine;
using UnityEngine.XR.Management;
public class startXR : MonoBehaviour
{
public bool xrStart;
public void Start()
{
if (xrStart)
{
StartCoroutine(StartXR());
}
else
{
StopXR();
}
}
public IEnumerator StartXR()
{
Debug.Log(“Initializing XR…”);
yield return XRGeneralSettings.Instance.Manager.InitializeLoader();
if (XRGeneralSettings.Instance.Manager.activeLoader == null)
{
Debug.LogError(“Initializing XR Failed. Check Editor or Player log for details.”);
}
else
{
Debug.Log(“Starting XR…”);
XRGeneralSettings.Instance.Manager.StartSubsystems();
}
}
void StopXR()
{
Debug.Log(“Stopping XR…”);
XRGeneralSettings.Instance.Manager.StopSubsystems();
XRGeneralSettings.Instance.Manager.DeinitializeLoader();
Debug.Log(“XR stopped completely.”);
}
}
yes!

In which line does it fail now? When running on the device.
if (XRGeneralSettings.Instance.Manager.activeLoader == null)
{
Debug.LogError("Initializing XR Failed. Check Editor or Player log for details.");
}
the error pops up at line 29 but not sure what is causing the error
Perhaps easiest then to start over with a brand new project, and make it run with the demo scene?
When the basics is up and running, then disable the “Initialize VR on Startup” and put back this custom code.
so i followed these instructions: Hướng dẫn nhanh về Google Cardboard dành cho Unity | Google for Developers
built the app but when i launch it, it launches in 2d not VR - is that right? The documentation seems to suggest it should launch in 3d
So i added the script:
using System.Collections;
using UnityEngine;
using UnityEngine.XR.Management;
public class startXR : MonoBehaviour
{
public bool xrStart;
public void Start()
{
if (xrStart)
{
StartCoroutine(StartXR());
}
else
{
StopXR();
}
}
public IEnumerator StartXR()
{
Debug.Log("Initializing XR...");
yield return XRGeneralSettings.Instance.Manager.InitializeLoader();
if (XRGeneralSettings.Instance.Manager.activeLoader == null)
{
Debug.LogError("Initializing XR Failed. Check Editor or Player log for details.");
}
else
{
Debug.Log("Starting XR...");
XRGeneralSettings.Instance.Manager.StartSubsystems();
}
}
void StopXR()
{
Debug.Log("Stopping XR...");
XRGeneralSettings.Instance.Manager.StopSubsystems();
XRGeneralSettings.Instance.Manager.DeinitializeLoader();
Debug.Log("XR stopped completely.");
}
}
and start off with a 2d scene. When I run it in the editor I get this error on 2d:
NullReferenceException: Object reference not set to an instance of an object
startXR.StopXR () (at Assets/Samples/Google Cardboard XR Plugin for Unity/1.8.0/Hello Cardboard/Scripts/startXR.cs:42)
startXR.Start () (at Assets/Samples/Google Cardboard XR Plugin for Unity/1.8.0/Hello Cardboard/Scripts/startXR.cs:18)
and this when i switch to the HelloCardboard scene
Please initialize Cardboard XR loader before calling this function.
UnityEngine.Debug:LogError(Object)
Google.XR.Cardboard.Api:UpdateScreenParams() (at Library/PackageCache/com.google.xr.cardboard@d9f0aa2eb0/Runtime/Api.cs:295)
CardboardStartup:Update() (at Assets/Samples/Google Cardboard XR Plugin for Unity/1.8.0/Hello Cardboard/Scripts/CardboardStartup.cs:70)
No…, the demo should launch in VR. Check the “Initialize XR on Startup” for that. You should probably look at the NullReferenceException, also. Dont think it belongs to the demo scene. Just follow the steps.
Based on earlier posts I understood this had to be unchecked on launch.
i have checked it and still get this error:
Please initialize Cardboard XR loader before calling this function
Can you help me fix that?
thanks
Please can someone help on this? I have been bouncing around forums and threads on this all weekend but have been unable to find a solution. I have tried on a new clean app and in my existing set up but just get the same errors: Please initialize Cardboard XR loader before calling this function.
Coping the code from the Unity Documentation:
using System.Collections;
using UnityEngine;
using UnityEngine.XR.Management;
public class ManualXRControl
{
public IEnumerator StartXR()
{
Debug.Log("Initializing XR...");
yield return XRGeneralSettings.Instance.Manager.InitializeLoader();
if (XRGeneralSettings.Instance.Manager.activeLoader == null)
{
Debug.LogError("Initializing XR Failed. Check Editor or Player log for details.");
}
else
{
Debug.Log("Starting XR...");
XRGeneralSettings.Instance.Manager.StartSubsystems();
}
}
void StopXR()
{
Debug.Log("Stopping XR...");
XRGeneralSettings.Instance.Manager.StopSubsystems();
XRGeneralSettings.Instance.Manager.DeinitializeLoader();
Debug.Log("XR stopped completely.");
}
}
Fails here:
if (XRGeneralSettings.Instance.Manager.activeLoader == null)
{
Debug.LogError("Initializing XR Failed. Check Editor or Player log for details.");
}
I have created a new 3D project and followed each line of the instructions. I am running 2019.4.31fi
In Editor
I have tried running the sample HelloWorldVR scene and get these errors. It doesn’t matter if i check the Initialise XR on start up box:
Please initialize Cardboard XR loader before calling this function.
UnityEngine.Debug:LogError (object)
Google.XR.Cardboard.Api:UpdateScreenParams () (at Library/PackageCache/com.google.xr.cardboard@d9f0aa2eb0/Runtime/Api.cs:295)
CardboardStartup:Update () (at Assets/Samples/Google Cardboard XR Plugin for Unity/1.8.0/Hello Cardboard/Scripts/CardboardStartup.cs:70)
If I comment out this line it stops the errors
Api.UpdateScreenParams();
In app
If I comment out this line it stops the errors
Api.UpdateScreenParams();
If I leave the Initialise XR on startup un checked then it doesn’t launch in split screen
If I check the box then it launches in split screen but the view doesn’t change as I move my head
If I don’t comment out
Api.UpdateScreenParams();
HelloWorldVR works
So I tried copying over CardboardStartup into a new VR scene
If I turn off the toggle for Initialise XR on start up box start with a 2D screen then switch to VR, it remains in 2D it doesn’t go split screen
If I leave that toggle on and only launch my VR scene it still stays in 2D
So I tried adding the toggle script and that made no difference.
Is there no definitive answer on this? It seems a fair few people have hit the same problem. According to this post it was fixed about a year ago so should be part of the 1.8.0 plugin?
This is doing my head and any help in resolving once and for all would be much appreciated
thanks
How about breaking up the StartXR into a method, thats starts Coroutine? Like this:
bool vron;
public void StartXR() {
StartCouroutine(StartXRRoutine());
)
public IEnumerator StartXRRoutine()
{
if (vron)
yield break;
vron = true;
Debug.Log("Initializing XR...");
yield return XRGeneralSettings.Instance.Manager.InitializeLoader();
if (XRGeneralSettings.Instance.Manager.activeLoader == null)
{
Debug.LogError("Initializing XR Failed. Check Editor or Player log for details.");
vron = false;
}
else
{
Debug.Log("Starting XR...");
XRGeneralSettings.Instance.Manager.StartSubsystems();
}
}
And add vron = false; to the StopXR() method.
i tested the sample scenes from 1.8 in empty project, switch between 2d/3d worked,
i think it had the error message “initialize first before calling”, but no crash.
then used my vrmanager code above, to switch and fix aspect ratio, no crash, no error messages, and did disable initial VR mode, so it starts in 2D.
(samsung s10e)
I wish I could do that! I have tested on Motorola Moto G(7) and do not get this result. When you say you can switch between VR and 2d in the test project, do you mean you set up new 2d scene and added in your code? “i tested the sample scenes from 1.8 in empty project, switch between 2d/3d worked,” I only see two scenes in sample project HelloCardboard VR and VrMode which I believe are both in 3D?
I have added 2d scenes to switch between but perhaps this was unnecessary?