Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to runtime initialize SteamVR?

Discussion in 'VR' started by rob_vld, Feb 8, 2021.

  1. rob_vld

    rob_vld

    Joined:
    Jul 9, 2013
    Posts:
    190
    Hello,

    With SteamVR using Legacy i have in Project Settings -> Player -> XR Settings I have added and placed "None" as my first device with "OpenVR" placed second.

    With the script execution order i placed a script to be listed first where i execute the following:

    Code (CSharp):
    1.  
    2. private void Awake()
    3. {
    4.     StartCoroutine(EnableVirtualReality());
    5. }
    6.  
    7. private IEnumerator EnableVirtualReality()
    8. {
    9.     XRSettings.LoadDeviceByName("OpenVR");
    10.     XRSettings.enabled = true;
    11.     SteamVR_Actions.PreInitialize();
    12.     SteamVR.Initialize(true);
    13.  
    14.     yield return null;
    15. }
    16.  
    On application start, the [CameraRig] is disabled and i am given an error:
    Once i enable the [CameraRig] over time(required) i am getting the following error 2x (Probably for the controllers):
    The VR Camera is working properly however the controllers are not.

    I have this working properly in a different project, but i can no longer figure out what i am doing wrong...
    Any suggestions?

    Unity3D: 2019.4.19f1
    Valve SteamVR Plugin: 2.7.2

    Thanks!
     
  2. resakosix

    resakosix

    Joined:
    Sep 26, 2012
    Posts:
    5
    I got it working with this:

    Code (CSharp):
    1.         XRGeneralSettings.Instance.Manager.InitializeLoaderSync();
    2.         XRGeneralSettings.Instance.Manager.StartSubsystems();


    The thing that in the editor, steam doesn't open until I execute the previous code, but in build, it auto opens at launch.
    I have disabled "Initialize XR on startup" from XR Plug-In-Management and "Auto enable vr" from steamvr_settings, but it starts automatically when launching the build.

    ¿Any idea what else do I have to configure to prevent steam from initializing at start on build?
     
    astracat111 likes this.
  3. rob_vld

    rob_vld

    Joined:
    Jul 9, 2013
    Posts:
    190
    Thank you for replying!

    Your issue is exactly why i asked for help with SteamVR - Legacy.
    As i said, i have a project where i -can- control this, but i cannot get it done in a new project.

    I would prefer of course to know how to do this with the new Unity XR Plugin Manager
    I made another failed attempt...
    I do think the best route is to disable/unload the plugin providers on application start somehow... and else inversed...

    so if anyone knows?
     
    Last edited: Feb 9, 2021
    benaclejames likes this.
  4. VResearch

    VResearch

    Joined:
    Jan 6, 2021
    Posts:
    21
    I had this problem once and what helped me was to run ActivateRig( rigSteamVR ); manually at some point. Take a look at Player.cs and how it handles switching back and forth. Also, check if the debug button (2D Debug/VR) works and how is implemented
     
  5. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    725
    This was hugely helpful just now.
     
  6. emongev

    emongev

    Joined:
    Jul 5, 2012
    Posts:
    36
    I'm having the exact same issue, i have no idea how to prevent SteamVR from starting except creating a separate build with OpenVR Loader disabled. Did you manage to fix it?
     
    paladim and Zatagado like this.
  7. Zatagado

    Zatagado

    Joined:
    Aug 17, 2018
    Posts:
    2
    I am also currently trying to tackle this same issue with SteamVR starting when the application starts.
     
  8. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    725
    So...

    Oculus Quest 2, I've got it working but not using the OpenXR runtime or SteamVR, only when selecting the Oculus runtime and building to that. Otherwise, there's a bar on the lower part of the screen...

    The thing to try though is to download previous versions of the OpenXR .dll, build the project, then just replace the OpenXR .dll with the one you want. You can also use AMDs new upscaling algorithm....MAYBE... this way?

    Personally I haven't tried it yet, but excited to give it a shot. I would suggest that if you have any troubles with the latest version of the OpenXR .dll just download previous versions, replace, and see what happens.

    VR is just one of those new platforms that's constantly being updated and changed, so you need to watch out when updating, always read the release notes of OpenXR if you're building to that platform, and if Unity doesn't keep up with the latest runtime you can try swapping some .dll files after you build your game.

    Already VR has come a long way since 4 years ago with the GearVR and Cardboard, and it's getting easier and easier to develop for by the day. Here's hoping that Oculus, Valve, etc... can work out the development kinks in the future and streamline everything to be as bug free as dealing with Unity.