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

Automatic XRLoader selection

Discussion in 'VR' started by NielsTerHeijden, Apr 3, 2020.

  1. NielsTerHeijden

    NielsTerHeijden

    Joined:
    Mar 4, 2014
    Posts:
    20
    I'm trying to switch over to the new XR plugin system. But ran into a problem when I added multiple Plugin Providers in de XR Plugin Management windows.

    When starting a scene unity tries to initialize the first XR plugin. This will fail and produce some errors in the console. Then the next XR plugin is tried. The Windows XR Plugin even triggers a windows popup window asking if you want to setup Windows MR.

    This makes this not really usable. I've tried to disable the Initialize on Startup option and then manually initializing the XR plugins but this gives the same result.

    I can't seem to find a way to check whether a certain HMD is connected to the system before initializing a XR plugin. And initializing a XR Plugin (not starting it) will already produce error messages in console or windows popups to appear.

    Is there a better way to check which HMD is connected and what XR plugin should be initialized?
     
    julienkay likes this.
  2. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,924
    I can't help, but ... I asked about this in one of the main threads about a week ago, and got no reply. It seems no-one has got this far yet :) with trying to support actual deployment.

    (technically, bits of XR are still pre-release, so ... I guess that's OK? But since we're already using it for production stuff, I'd like to make a better experience).

    I suggest: Upload your project using the "Window > Submit a bug report" feature in Editor. That way they'll be forced to either close it with a pointer to instructions on how to workaround this - or it will prod them to hurry up and add programmatic access so we can handle it ourselves :)
     
    julienkay likes this.
  3. julienkay

    julienkay

    Joined:
    Nov 12, 2013
    Posts:
    167
    I'm currently hitting the same issue. There is currently no way to build a multi-platform VR app. Windows will shove a popup to the users face requesting them to install Windows Mixed Reality, even if the user intends to use the app with the Oculus or OpenVR platform (or even in desktop mode).
    (A detail I noticed is, that this popup only appears for non-admin accounts, which makes it even more likely that this isn't caught during development.

    To be fair, this is probably partly Microsofts fault, but I still hope someone from Unity sees this and can fix it. I'll try to send a bug report too.
     
  4. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    There isn't much Unity can do about this since that pop up is an internal part of the Windows OS and nothing we have control over.
     
  5. julienkay

    julienkay

    Joined:
    Nov 12, 2013
    Posts:
    167
    I see your point, that part is outside of your control. But one could argue that it's completely reasonable for Windows to show that message, because the XR Plugin Management is actually triggering initialization of WMR through the WindowsMRLoader. As far as Windows is concerned, the software wants to start using Mixed Reality.

    It seems it's not possible to detect whether a certain headset is connected, before starting the associated XR plugin? The recommended way is to cycle through all plugins, start them and see which loader succeeds? (Please correct me if I'm wrong)

    Anyways, I've resorted to disabling "Initialize on Startup" in the XR Plugin Management settings and handling the loading myself, where I only start the WindowsMRPlugin if Windows Mixed Reality Portal is actually installed. This way the XR platform detection can fall through to other platforms or desktop mode.
    But imho this should be the default behaviour.
     
  6. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    How do you tell if MRP is installed?
     
  7. julienkay

    julienkay

    Joined:
    Nov 12, 2013
    Posts:
    167
    I check the registry value "FirstRunSucceeded" in "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Holographic":
    If it's 0 or not present, WMR is not installed. After installation the value is 1.

    Surely not the most robust way, but it works for now.
     
    Last edited: Sep 15, 2022
  8. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    Thanks.
     
  9. RickEllis

    RickEllis

    Joined:
    Dec 10, 2016
    Posts:
    6
    Hello! How are you reading the registry from Unity? I've been looking all over for a method to do this and have come up empty. Thank you.
     
  10. julienkay

    julienkay

    Joined:
    Nov 12, 2013
    Posts:
    167
    You'll need to set API Compatibility Level to ".NET Framework" (".NET 4.x" in earlier Unity versions).
    Then you can use something like the following:

    Code (CSharp):
    1. public static bool IsWindowsMixedRealityInstalled() {
    2.     Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Holographic");
    3.     int val = (int)key.GetValue("FirstRunSucceeded", -1);
    4.     return val == 1;
    5. }
    This is Windows-specific code, so you might want to wrap it with an
    #if UNITY_STANDALONE_WIN
     
    RickEllis and a436t4ataf like this.
  11. RickEllis

    RickEllis

    Joined:
    Dec 10, 2016
    Posts:
    6
    Thank you, setting the compatibility level to ".NET Framework" did the trick. Like many, I was looking for .Net 4.x... I have it all running now. Thanks again!