Manual OpenXR Load with Unity Input System not working

I have a 2020.3 project and I have Initialize XR on Startup in Project Settings set to false because I want to manually start VR. Then, in my input monobehaviour Awake I write:

XRGeneralSettings.Instance.Manager.InitializeLoaderSync();
XRGeneralSettings.Instance.Manager.StartSubsystems();

Then I call my input.actions.Enable();

If I have my Index headset turned off, I have to press Play in the editor TWICE for SteamVR to turn on. But input isn’t recognized in either play.

If I have Initialize XR on Startup set to true, then SteamVR handles my input properly (but after running Play twice as well).

What gives?

Using Unity 2020.3.0f1
SteamVR beta 1.16.10
OpenXR Plugin 1.0.2
Input System 1.0.2

Would it be possible for your to provide a project to reproduce this with?

The problem was that there was a warning I wasn’t seeing:
“XR Management has already initialized an active loader in this scene.Please make sure to stop all subsystems and deinitialize the active loader before initializing a new one.”

And this did not allow me to use VR. This shouldn’t be a warning, it should be an error as everything continues on as active but without functionality.

The fix was to StopSubsystems and Deinitialize the active loader BEFORE initializing it. This should be an addendum to everyone else who Googled a fix for manually initializing OpenXR:

public void Awake(){
        //fix
        if( XRGeneralSettings.Instance.Manager.activeLoader != null ){
            XRGeneralSettings.Instance.Manager.StopSubsystems();
            XRGeneralSettings.Instance.Manager.DeinitializeLoader();
        }
        XRGeneralSettings.Instance.Manager.InitializeLoaderSync();
        XRGeneralSettings.Instance.Manager.StartSubsystems();

        var actions = new InputActions();
        actions.Enable();

        actions.vrControls.leftAnalogPos.performed += ctx => Debug.LogError( ctx.ReadValue<Vector2>() );
    }

Thanks.

1 Like

The docs talk about this pretty well: End-user documentation | XR Plugin Management | 4.0.7, including sample for manually managing this exact thing.

If you feel that the warnings should be errors, please file a bug and post the case id here.

1 Like

Think there is something more going on here, because i’m having the same issue the OG poster is describing.

  1. If you uncheck Initialize XR on Startup, enter play mode then start the loader manually in code
  2. Stop Play mode
  3. Start play mode again - it automatically loads the first loader in the list.
  4. Re-enable Initialize XR on Startup and enter play mode
  5. Immediately receive the following error - clearly it’s trying to load it twice “automatically”

XR Management has already initialized an active loader in this scene.Please make sure to stop all subsystems and deinitialize the active loader before initializing a new one.
UnityEngine.XR.Management.XRGeneralSettings:AttemptInitializeXRSDKOnLoad () (at Library/PackageCache/com.unity.xr.management@4.0.1/Runtime/XRGeneralSettings.cs:148)

It’s almost as if the loader from the previous play mode is still “active”. Which sounds strange, but nothing else makes sense.

Definitely a XR Plugin Management issue. Not OpenXR, because I’m only testing manually loading of the Oculus plugin right now.

Unity 2020.3
XR Plugin Management 4.0.1
Edit: Tested in 2019.4.20 and has the same behaviour.

Upon further testing, this will happen if you stopped your play session in the editor without cleaning up the Manually loaded XR SubSystems.

I cleaned up the Subsystems in OnApplicationQuit, and upon the next play session the “previous loader” is no longer there causing the trouble.

2 Likes

THANK YOU. I wasn’t even initiatizing XR in script, but since upgrading to Unity 2019.4 I was suddenly only able to run VR in playmode once. This fixed me.

2 Likes

Cheerfully still broken in November 2022 and thank you SO much for the fix!

Still a problem on 2021.3.14f, any updates?

Still a problem in 2021.3.31. I have 2 separate unity projects, one where this occurs and one where it doesn’t, trying to track down the difference but no luck and can’t seem to figure out why one is initializing a loader before my code tells it to with the “Initialize XR on Startup” unchecked…

I had the same problem after setting up a basic scene with an XR Rig on Unity 2022.3.13f1 with automatic XR Loading
The play mode only worked once in VR (using Quest Link) and then I had to restart Unity for it to work again

sgthale code seems to have fixed the problem to

Still broken in 2022.3.0. I love living in the future

1 Like

I got the same issue solved by deleting the temp , library ,vs and obj folders then reopen unity

Still broken. Delete temp, lib, vs and obj if you want. Alternatively throw this script in somewhere at the start or in a developer tool until you isolate where you start loader. Same as the one above

    public void Awake() {
        // Fix: Stop subsystems and deinitialize the loader if it's already active
        if (XRGeneralSettings.Instance.Manager.activeLoader != null) {
            XRGeneralSettings.Instance.Manager.StopSubsystems();
            XRGeneralSettings.Instance.Manager.DeinitializeLoader();
        }

        // Initialize and start the loader
        XRGeneralSettings.Instance.Manager.InitializeLoaderSync();
        XRGeneralSettings.Instance.Manager.StartSubsystems();
}
1 Like