Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Manual OpenXR Load with Unity Input System not working

Discussion in 'XR Interaction Toolkit and Input' started by sgthale, Mar 16, 2021.

  1. sgthale

    sgthale

    Joined:
    Mar 10, 2018
    Posts:
    11
    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:

    Code (CSharp):
    1. XRGeneralSettings.Instance.Manager.InitializeLoaderSync();
    2. 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
     
  2. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467

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

    sgthale

    Joined:
    Mar 10, 2018
    Posts:
    11
    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:

    Code (CSharp):
    1. public void Awake(){
    2.         //fix
    3.         if( XRGeneralSettings.Instance.Manager.activeLoader != null ){
    4.             XRGeneralSettings.Instance.Manager.StopSubsystems();
    5.             XRGeneralSettings.Instance.Manager.DeinitializeLoader();
    6.         }
    7.         XRGeneralSettings.Instance.Manager.InitializeLoaderSync();
    8.         XRGeneralSettings.Instance.Manager.StartSubsystems();
    9.  
    10.         var actions = new InputActions();
    11.         actions.Enable();
    12.  
    13.         actions.vrControls.leftAnalogPos.performed += ctx => Debug.LogError( ctx.ReadValue<Vector2>() );
    14.     }
    Thanks.
     
  4. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
  5. Cloudwalker_

    Cloudwalker_

    Joined:
    Jan 3, 2014
    Posts:
    134
    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.
     
    Last edited: Mar 21, 2021
  6. Cloudwalker_

    Cloudwalker_

    Joined:
    Jan 3, 2014
    Posts:
    134
    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.
     
    FileThirteen and sewy like this.
  7. silentpundit

    silentpundit

    Joined:
    May 2, 2020
    Posts:
    26
    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.

     
    VRDave_Unity likes this.
  8. djarcas

    djarcas

    Joined:
    Nov 15, 2012
    Posts:
    234
    Cheerfully still broken in November 2022 and thank you SO much for the fix!
     
  9. thomasvaniseghemSB

    thomasvaniseghemSB

    Joined:
    Sep 15, 2022
    Posts:
    12
    Still a problem on 2021.3.14f, any updates?
     
  10. ceitel

    ceitel

    Joined:
    Jan 3, 2017
    Posts:
    34
    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...