steamvr_unity_plugin icon indicating copy to clipboard operation
steamvr_unity_plugin copied to clipboard

SteamVR instance is never initialized due to XRSettings.enabled being false

Open methusalah opened this issue 5 years ago • 16 comments

Context: Unity 2020.1.0, HDRP on Windows 10, with SteamVR Unity plugin 2.6.0 and the OpenVR XR plugin v1 preview 12. "Initialize XR on Startup" and "OpenVR loader" are both checked in Unity project settings, and SteamVR 1.13.10 in running on my computer (I also tested with SteamVR shut down).

Running the Interactions_Examples scene, the player's steam VR objects are disabled and the fallback objects are enabled. I observe the same in my game using a single SteamVR_Behavior_Pose. SteamVR instance is not initialized and a null exception is raised each frame.

I've debbuged it a little and it appears that SteamVR class instance is never initialized because XRSettings.enabled is false. The only code path where XRSetting.enabled is set to true is by using the boolean "forceUnityVRToOpenVR" to true, which is only used in the component SteamVR_ForceSteamVRMode, as far as I understand. Of course, XRSettings.enabled could also be set to true in the Unity side but it is not in my situation.

Is there something I'm doing wrong here?

methusalah avatar Aug 02 '20 19:08 methusalah

Looked into it a little more, try just deleting lines 33/34 in SteamVR.cs that check to see if XRSettings.enabled is true

keithbradner avatar Aug 02 '20 19:08 keithbradner

Ok that seem to allow me to run without issue, thanks!

Unfortunatly, I've got a systematic Unity crash when I leave play mode now. I suppose it is related since it appeared just after that only code modification. Here are Unity and SteamVR logs.

Editor.log error.log SteamVR-2020-08-02-PM_10_16_52.txt

methusalah avatar Aug 02 '20 20:08 methusalah

How about this instead of just deleting that section:

#if UNITY_2020_1_OR_NEWER
                if (!XRSettings.isDeviceActive)
                    enabled = false;
#else
                if (!XRSettings.enabled)
                    enabled = false;
#endif

Sorry I'm having you test this, I'm just not able to repro locally.

keithbradner avatar Aug 02 '20 21:08 keithbradner

In this configuration, the SteamVR inctance is not instanced because XRSettings.isDeviceActive is always false during play time.

I can stop the playmode without crash.

But now, Unity crashes 50% times on enter playmode. I've noticed that if SteamVR is not running when a crash on enter play mode occur, it is not started at all.

I have also noticed thath SteamVR is not started when I open my Unity project, as it was back with 2019. Now it is only started when the game enters play mode. I don't know if any of this is relevant.

Don't hesitate if you need more information or have things to make me test.

methusalah avatar Aug 02 '20 22:08 methusalah

I've build a new project and now I do not experience craches anymore with XRSettings.isDeviceActive. Yet, it is still always false and SteamVR instance never initialize.

I've noticed that sometimes, randomly, if SteamVR is not running, launching unity and even entering playmode won't start it. Resulting in this warning: "[SteamVR] Initialization failed. VR may be disabled in player settings. Go to player settings in the editor and check the 'Virtual Reality Supported' checkbox'. OpenVR is not in your list of supported virtual reality SDKs. Add it to the list in player settings. To force OpenVR initialization call SteamVR.Initialize(true). "

My process for building the project:

  • create a new HDRP project with Unity 2020.1
  • import XR plugin management
  • import the latest SteamVR unity plugin unitypackage, which import OpenVR XR plugin and activate itself in the settings.
  • copy my assets folder (except the SteamVR folders) from my working project to the new one.

Nothing fancy I suppose. I don't copy any library, binary, settings or whatnot. Only assets.

methusalah avatar Aug 02 '20 23:08 methusalah

I am glad you pointed this one out because i am having the same issue. I didn't know what the problem was I only knew player's steamVR objects are always disabled in play mode. Also I think it only happens with HDRP projects because i created new URP project and it worked just fine. My setup:

  • HDRP project
  • unity 2019.3.15f1
  • the latest steamVR unity plugin and OpenVR XR plugin

matejdubec avatar Aug 03 '20 16:08 matejdubec

@matejdubec Can you debug and confirm that the issue is the same for you, having both XRSettings.enabled and XRSettings.isDeviceActive to false at all time during playmode?

This would tend to confirm that it is not a regression introduced by Unity 2020.1

methusalah avatar Aug 03 '20 16:08 methusalah

@matejdubec Can you debug and confirm that the issue is the same for you, having both XRSettings.enabled and XRSettings.isDeviceActive to false at all time during playmode?

This would tend to confirm that it is not a regression introduced by Unity 2020.1

Yes but not before tomorrow (i don't have access to VR headset right now) but everything you described happened to me. I've got [SteamVR] Initialization failed warning as well as 'SteamVR_Behavior_Pose. SteamVR instance is not initialized and a null exception error. Also my controllers were visible after deleting lines 33/34 SteamVR.cs

matejdubec avatar Aug 03 '20 16:08 matejdubec

Just to confirm, you're both on beta 4 of the steamvr_unity_plugin, right? I tried the repro steps and am not able to produce any errors. Can one of you send me a barebones project that doesn't work?

keithbradner avatar Aug 03 '20 20:08 keithbradner

I'm using SteamVR unity plugin 2.6.0b4. I will try and make you a minimal project with the error.

methusalah avatar Aug 03 '20 20:08 methusalah

I've been able to reproduce the bug on a minimal project. You will find it via google drive here.

The process:

  • create a new HDRP project with Unity 2020.1.0f1,
  • into project settings, import XR plugin management,
  • import the unitypackage of SteamVR Unity Plugin v2.6.0b4 found here ,
  • OpenVR XR plugin is imported automatically in the process, and both "Initialize XR on Startup" and "OpenVR Loader" are checked,
  • in the sample scene, create a cube and add a SteamVR_behavior_pose component on it.

I've also removed the standard asset to save file weight.

methusalah avatar Aug 03 '20 21:08 methusalah

Thanks for the project, I was able to repro with it. Give this a try: https://drive.google.com/file/d/19rb9dATOtlW-h7iyUlgujWdcS2LqK56M/view

keithbradner avatar Aug 03 '20 23:08 keithbradner

Thank you @keithbradner, it solved the issue for me. SteamVR class instance is correctly initialized and I have experienced no crash so far.

Great job!

methusalah avatar Aug 04 '20 08:08 methusalah

I can confirm, it solved the issue for me as well. However I had to change the version in SteamVR.cs on line 33 but I'll be upgrading to newer version anyway so that's not a problem. Thank you very much!

matejdubec avatar Aug 04 '20 15:08 matejdubec

Great job! You deserve an asado! thank you so much @keithbradner! You are my hero now xD

kinacho2 avatar Aug 13 '20 15:08 kinacho2

I had this issue in 2019.3.14, so like @matejdubec I also had to change line 33 in SteamVR.cs once I imported package version 2.6.1. My code is: #if UNITY_2019_3_OR_NEWER Works as intended now, thanks!

ary1111 avatar Aug 18 '20 19:08 ary1111