Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenVR Loader initializes regardless of Unity XR "Initialize XR on Startup" option. #80

Open
nitz opened this issue Feb 25, 2021 · 12 comments · May be fixed by #102
Open

OpenVR Loader initializes regardless of Unity XR "Initialize XR on Startup" option. #80

nitz opened this issue Feb 25, 2021 · 12 comments · May be fixed by #102

Comments

@nitz
Copy link

nitz commented Feb 25, 2021

Hello!

I've been in the process of moving from a much older version of OVR/SteamVR to the new Unity XR Plug-in system. Most things have been pretty straight forward, but with this project I've hit a blocking issue: this application needs to be running two instances.

Currently, regardless of build settings, opening a second instance causes the first to immediately quit, as it has initialized the VR hardware. (I'm using a Vive Pro Eye at the moment, not sure if that matters.)

Previously we were able to work around this issue by building the project twice: once with "VR Enabled" checked and once with "VR Enabled" unchecked. That would allow us to start one of the instance where it was enabled, and then any other number of instances with the disabled one. I've tried scripting the adjustment of XRGeneralSettings.Instance.InitManagerOnStart to both true and false for building two instances of the player too, but it doesn't seem to make a difference there either.

I'm attempting to replicate that now, but it seems the OpenVR Loader plugin completely ignores the "Initialize XR on Startup" option. Regardless of that setting, OpenVR seems to initialize and open the hardware, because opening another instance always causes the first to close.

Ideally I'd like to be able to have just a single build, and then either launch to a "chooser" scene that would allow me to go the VR route or the non-VR route, but it seems no solution is working at the moment, or I'm misunderstanding the systems.

Is there something I'm missing or doing wrong, or is this a defect?

Below are some screenshots of the settings I'm trying.

image

image

Here is the tiny build script I use to build two copies of the player build script gist.

@zite
Copy link
Collaborator

zite commented Feb 26, 2021

Maybe you're running SteamVR related scripts that are triggering Unity XR? Try setting an empty scene as your startup scene and see if you encounter the same issue.

@nitz
Copy link
Author

nitz commented Feb 26, 2021

I created an empty scene and changed my build script to reference only that scene. Opening a new instance still causes the first instance to close. I'm trying to get a build going with minimal managed/native plugins to see if it's something in one of those causing it to kick off, but the logs don't make it look like anything, and the close seems "graceful".

@nitz
Copy link
Author

nitz commented Feb 26, 2021

I added a script to print out my XRSettings in an [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)], and was taking a look at the message above my message. Looks like the XR devices are getting scanned and matched before it unity ever even creates the GfxDevice, while it's setting up the subsystem scaffolding. Interestingly enough, it does seem like my InitManagerOnStart is false like I had hoped, just doesn't seem to be doing what I'd want 😅

Mono path[0] = 'C:/Users/cmd/Desktop/output/PROJECT_viewer/viewer_Data/Managed'
Mono config path = 'C:/Users/cmd/Desktop/output/PROJECT_viewer/MonoBleedingEdge/etc'
Initialize engine version: 2020.2.6f1 (8a2143876886)
[Subsystems] Discovering subsystems at path C:/Users/cmd/Desktop/output/PROJECT_viewer/viewer_Data/UnitySubsystems
[Subsystems] No descriptors matched for  examples in UnitySubsystems/UnityMockHMD/UnitySubsystemsManifest.json.
[Subsystems] 1 'inputs' descriptors matched in UnitySubsystems/UnityMockHMD/UnitySubsystemsManifest.json
[Subsystems] 1 'displays' descriptors matched in UnitySubsystems/UnityMockHMD/UnitySubsystemsManifest.json
[Subsystems] No descriptors matched for  meshings in UnitySubsystems/UnityMockHMD/UnitySubsystemsManifest.json.
[Subsystems] No descriptors matched for  examples in UnitySubsystems/XRSDKOpenVR/UnitySubsystemsManifest.json.
[Subsystems] 1 'inputs' descriptors matched in UnitySubsystems/XRSDKOpenVR/UnitySubsystemsManifest.json
[Subsystems] 1 'displays' descriptors matched in UnitySubsystems/XRSDKOpenVR/UnitySubsystemsManifest.json
[Subsystems] No descriptors matched for  meshings in UnitySubsystems/XRSDKOpenVR/UnitySubsystemsManifest.json.
GfxDevice: creating device client; threaded=1
Direct3D:
    Version:  Direct3D 11.0 [level 11.1]
    Renderer: NVIDIA GeForce RTX 2080 Ti (ID=0x1e04)
    Vendor:   
    VRAM:     11049 MB
    Driver:   27.21.14.6140
Begin MonoManager ReloadAssembly
- Completed reload, in  0.069 seconds
XRGeneral Settings awakening...

D3D11 device created for Microsoft Media Foundation video decoding.
[I][20:12:38.775339][] Log started.

[I][20:12:38.775839][] Subsystems registered.

[I][20:12:38.776340][] Running after assemblies loaded...

[I][20:12:38.870840][] XR Settings: {
  "Manager": {
    "automaticLoading": false,
    "automaticRunning": false,
    "loaders": [
      {
        "displaySubsystem": null,
        "inputSubsystem": null,
        "name": "Open VR Loader",
        "hideFlags": 0
      }
    ],
    "activeLoaders": [
      {
        "displaySubsystem": null,
        "inputSubsystem": null,
        "name": "Open VR Loader",
        "hideFlags": 0
      }
    ],
    "isInitializationComplete": false,
    "activeLoader": null,
    "name": "Standalone Providers",
    "hideFlags": 0
  },
  "AssignedSettings": {
    "automaticLoading": false,
    "automaticRunning": false,
    "loaders": [
      {
        "displaySubsystem": null,
        "inputSubsystem": null,
        "name": "Open VR Loader",
        "hideFlags": 0
      }
    ],
    "activeLoaders": [
      {
        "displaySubsystem": null,
        "inputSubsystem": null,
        "name": "Open VR Loader",
        "hideFlags": 0
      }
    ],
    "isInitializationComplete": false,
    "activeLoader": null,
    "name": "Standalone Providers",
    "hideFlags": 0
  },
  "InitManagerOnStart": false,
  "name": "Standalone Settings",
  "hideFlags": 0
}

@zite
Copy link
Collaborator

zite commented Feb 26, 2021

Hmm, and just to check your Player Settings -> Resolution -> Force Single Instance setting is not checked, right?

@nitz
Copy link
Author

nitz commented Feb 26, 2021

Affirmative, along with allowing run in background.

image

@nitz
Copy link
Author

nitz commented Feb 26, 2021

I've set up the scaffolding of an empty project to get a minimum reproducible example. Ran into a small issue with that, but that's okay!

I imported the SteamVR Package which brought along the OpenVR plugin, and configured the project like mine:

Player Settings

  • Run in background
  • Force Single Instance

XR Plug-in Management

  • Initialize XR on Startup
    • Plugin Providers
    • OpenVR Loader

SteamVR_Resources/Resources/SteamVR_Settings.asset

  • Auto Enable VR

There is also a small script, BuildHooks.cs that has the RuntimeInitializeOnLoadMethod hooks in it to log when that code runs. It also prints the XRGeneralSettings.Instance & XRGeneralSettings.Instance.Manager as JSON.

I've included a build of the project, as well as the project itself. You can see the issue by running one instance of the build, wait for it to open, then starting a second instance. The first instance will close.

Github wasn't a fan of a 100MB zip file, so I've instead uploaded it here.

What else should I take a look at?

Thanks for the help so far!

@nitz
Copy link
Author

nitz commented Mar 1, 2021

Good morning!

Alright, I'm back with what seems to be a workaround for my case here at the moment! I'm writing this while my project is building with the full scenes, but this worked for me using the empty scene.

In my build script, for my "viewer" side of my application, I'm attempting to set the loaders to an empty list, like so:

public static bool BuildViewer()
{
	var bpo = GetDefaultBuildOptions();
	bpo.scenes = new[] { "Assets/viewer.unity" };
	bpo.locationPathName = ModifyLocationPathName(bpo.locationPathName, "PROJECT_viewer", "viewer");

	// hold on to current XR settings
	bool xrEnabled = XRSettings.enabled;
	bool xrInitManagerOnStart = XRGeneralSettings.Instance.InitManagerOnStart;
	var managerLoaders = new List<XRLoader>(XRGeneralSettings.Instance.Manager.activeLoaders);
	var assignedSettingsLoaders = new List<XRLoader>(XRGeneralSettings.Instance.AssignedSettings.activeLoaders);

	// set viewer specific XR settings
	XRSettings.enabled = false;
	XRGeneralSettings.Instance.InitManagerOnStart = false;
	XRGeneralSettings.Instance.Manager.TrySetLoaders(new List<XRLoader>());
	XRGeneralSettings.Instance.AssignedSettings.TrySetLoaders(new List<XRLoader>());

	// do the build
	bool buildResult = Build(bpo);
	
	// return the loaders to their previous configuration
	XRSettings.enabled = xrEnabled;
	XRGeneralSettings.Instance.InitManagerOnStart = xrInitManagerOnStart;
	XRGeneralSettings.Instance.Manager.TrySetLoaders(managerLoaders);
	XRGeneralSettings.Instance.AssignedSettings.TrySetLoaders(assignedSettingsLoaders);
	
	return buildResult;
}

I'm doing it to both .Manager and .AssignedSettings, but reflecting makes it look like they're the same internal variable?

// class XRGeneralSettings

public XRManagerSettings Manager
{
	get => this.m_LoaderManagerInstance;
	set => this.m_LoaderManagerInstance = value;
}

public XRManagerSettings AssignedSettings
{
	get => this.m_LoaderManagerInstance;
	set => this.m_LoaderManagerInstance = value;
}

But I figure best to just cover my bases.

Anyways, now when I run my 'viewer', which is what I don't want to have any XR enabled, the first lines of the output log now look like this:

Mono path[0] = 'C:/Users/cmd/Desktop/output/PROJECT_viewer/viewer_Data/Managed'
Mono config path = 'C:/Users/cmd/Desktop/output/PROJECT_viewer/MonoBleedingEdge/etc'
Initialize engine version: 2020.2.6f1 (8a2143876886)
Plugins: Failed to load 'XRSDKOpenVR' because one or more of its dependencies could not be loaded.

[Subsystems] Discovering subsystems at path C:/Users/cmd/Desktop/output/PROJECT_viewer/viewer_Data/UnitySubsystems
[Subsystems] No descriptors matched for  examples in UnitySubsystems/UnityMockHMD/UnitySubsystemsManifest.json.
[Subsystems] 1 'inputs' descriptors matched in UnitySubsystems/UnityMockHMD/UnitySubsystemsManifest.json
[Subsystems] 1 'displays' descriptors matched in UnitySubsystems/UnityMockHMD/UnitySubsystemsManifest.json
[Subsystems] No descriptors matched for  meshings in UnitySubsystems/UnityMockHMD/UnitySubsystemsManifest.json.
[Subsystems] No descriptors matched for  examples in UnitySubsystems/XRSDKOpenVR/UnitySubsystemsManifest.json.
[Subsystems] 1 'inputs' descriptors matched in UnitySubsystems/XRSDKOpenVR/UnitySubsystemsManifest.json
[Subsystems] 1 'displays' descriptors matched in UnitySubsystems/XRSDKOpenVR/UnitySubsystemsManifest.json
[Subsystems] No descriptors matched for  meshings in UnitySubsystems/XRSDKOpenVR/UnitySubsystemsManifest.json.
GfxDevice: creating device client; threaded=1
Direct3D:
    Version:  Direct3D 11.0 [level 11.1]
    Renderer: NVIDIA GeForce GTX 1070 (ID=0x1b81)
    Vendor:   
    VRAM:     8088 MB
    Driver:   27.21.14.5655
Begin MonoManager ReloadAssembly
- Completed reload, in  0.241 seconds
D3D11 device created for Microsoft Media Foundation video decoding.
[I][12:07:57.579901][] Log started.

[I][12:07:57.583401][] Subsystems registered.

[I][12:07:57.584402][] Running after assemblies loaded...

[I][12:07:57.623901][] XR Settings: null

[I][12:07:57.624401][] XR Manager Settings: null

Most notably, I think is this line before the subsystems: Plugins: Failed to load 'XRSDKOpenVR' because one or more of its dependencies could not be loaded., and of course, the XR Settings being null.

So it still even seems to be trying to load XRSDKOpenVR, but because it fails, the behavior is what I wanted! But perhaps that provides a clue as to where the "loading regardless of the init on startup" issue is coming from?

One more side note that might help us find the source. I also have the VIU in this project. Once after building with "Initialize XR on Startup" disabled, and "OpenVR Loader" unchecked, it prompted me to turn VR back on like so:

image

I clicked "Use recommended (True)". It re-enabled the "OpenVR Loader" checkbox in the XR Plug-in Management section, but still left "Initialize XR on Startup" disabled. So it was pleased enough to think Virtual Reality was enabled regardless of that checkbox too!

@Verex
Copy link

Verex commented Jul 30, 2021

I second this issue as it's still persistent in 1.1.4.

I have a solution and can do a PR but I want to make sure this is the same issue. @nitz does this only happen to you in a build? For me it didn't auto-initialize in-editor but in a build it would always auto-initialize and the SteamVR window would pop up.

@nitz
Copy link
Author

nitz commented Jul 30, 2021

I was only testing it in builds. My development machine isn't the same machine I typically use for testing, so I wasn't investigating it in the editor at all. I'm not in this particular project this week but can check sometime next week!

@Verex Verex linked a pull request Jul 30, 2021 that will close this issue
@Verex
Copy link

Verex commented Jul 30, 2021

@nitz I posted a PR for this that possibly fixes it. If you have time to test check out that request and if it solves your issue and please leave a comment on your results. Thanks!

@emongev
Copy link

emongev commented Aug 5, 2021

@Verex I had this exact same issue and your modifications definitely helped me with it, although now I'm having a critical error whenever I start SteamVR, although that may be completely unrelated, so really appreciate that pull request, you're a savior!

@nitz
Copy link
Author

nitz commented Aug 16, 2021

Remember how I said I hoped to check this out "next week" like 3 weeks ago, @Verex?

Well, I've finished putting out the fires I needed to for unrelated projects, and have finally got to give this a shot.

It worked fantastically. #102 should definitely be merged! Thanks for figuring it out!

zite added a commit that referenced this issue Mar 23, 2023
- Updated to SteamVR SDK 1.23.7
- Fix for unnecessary preinit #80
- Fix for incorrect reporting of eye position #86
- Fix for broken depth textures in some situations #110
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants