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. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Question Single Player with support for Multiple XR platforms

Discussion in 'AR/VR (XR) Discussion' started by eusebium, Nov 11, 2020.

  1. eusebium

    eusebium

    Joined:
    Jul 23, 2016
    Posts:
    80
    Hello,
    I would like to build a XR application that needs to run on multiple XR platforms - SteamVR, Oculus for Standalone.
    I am using MRTK as high-level abstraction layer but underneath it is using the Unity XR SDK.

    I would like to know if Unity supports this scenario because when I try to use both OpenVR XR Plugin and Oculus XR Plugin, the Oculus is always started first, even if SteamVR is running and HTC Vive is plugged in.
    upload_2020-11-11_22-48-20.png
     
  2. amirebrahimi_unity

    amirebrahimi_unity

    Unity Technologies

    Joined:
    Aug 12, 2015
    Posts:
    400
  3. eusebium

    eusebium

    Joined:
    Jul 23, 2016
    Posts:
    80
    Where and how should I move this then?
     
  4. amirebrahimi_unity

    amirebrahimi_unity

    Unity Technologies

    Joined:
    Aug 12, 2015
    Posts:
    400
    I moved your thread as a courtesy.
     
  5. KirillKuzyk

    KirillKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    953
    I haven't tried this myself, but here is an idea:
    1. Disable the 'Initialize XR on Startup' in XR Management Settings window.
    2. Then initialize your loader manually from code:
    Code (CSharp):
    1. var preferredLoader = XRGeneralSettings.Instance.Manager.loaders.Single(loader => loader is ENTER_PREFERRED_LOADER_TYPE_HERE);
    2. preferredLoader.Initialize();
     
  6. eusebium

    eusebium

    Joined:
    Jul 23, 2016
    Posts:
    80
    Thanks for your answer!

    That might work but I need to find out which device is actually plugged in.
    I tried using OpenVR API to get the manufacturer but this requires OpenVR.Init() to be called which somehow interferes with Unity XR.
    Also tried Unity XR API to get the devices but that needs to be initialized already...

    Code (CSharp):
    1. #if UNITY_STANDALONE && !UNITY_WSA && !UNITY_ANDROID
    2.             XRLoader preferredLoader = null;      
    3.             var loaders = XRGeneralSettings.Instance.Manager.loaders;
    4.  
    5.             bool isOculus = false;
    6.  
    7.             if (OpenVR.IsHmdPresent())
    8.             {
    9.                 EVRInitError err = EVRInitError.None;
    10.                 OpenVR.Init(ref err);
    11.  
    12.                 for (uint i = 0; i < 16; i++)
    13.                 {
    14.                     var sb = new StringBuilder((int)64);
    15.                     ETrackedPropertyError errp = ETrackedPropertyError.TrackedProp_NotYetAvailable;
    16.                     OpenVR.System.GetStringTrackedDeviceProperty(i, ETrackedDeviceProperty.Prop_ManufacturerName_String, sb, (uint)64, ref errp);
    17.  
    18.                     string value = sb.ToString();
    19.                     if (!string.IsNullOrEmpty(value))
    20.                     {
    21.                         isOculus = value.Contains("oculus");
    22.                         break;
    23.                     }
    24.                 }
    25.  
    26.                 //OpenVR.Shutdown();
    27.  
    28.                 if (isOculus)
    29.                     preferredLoader = loaders.SingleOrDefault(loader => loader is OculusLoader);
    30.                 else
    31.                     preferredLoader = loaders.SingleOrDefault(loader => loader is OpenVRLoader);
    32.  
    33.                 if (preferredLoader)
    34.                 {
    35.                     preferredLoader.Initialize();
    36.  
    37.                     XRGeneralSettings.Instance.Manager.StartSubsystems();
    38.                 }
    39.             }
    40. #endif
     
  7. EusebiuMarcuUCB

    EusebiuMarcuUCB

    Joined:
    Sep 20, 2018
    Posts:
    26
    Works as expected in 2020.2.3 - Unity detects the loader correctly.
     
  8. NemesisWarlock

    NemesisWarlock

    Joined:
    Jan 21, 2017
    Posts:
    139
    Multiplatform support SHOULD be fixed (eventually) with the move to OpenXR. I'd give it another year or so.