ValveSoftware / steamvr_unity_plugin

SteamVR Unity Plugin - Documentation at: https://valvesoftware.github.io/steamvr_unity_plugin/
BSD 3-Clause "New" or "Revised" License
1.03k stars 256 forks source link

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

Open methusalah opened 4 years ago

methusalah commented 4 years ago

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?

zite commented 4 years ago

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

methusalah commented 4 years ago

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

zite commented 4 years ago

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.

methusalah commented 4 years ago

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 commented 4 years ago

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:

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

matejdubec commented 4 years ago

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:

methusalah commented 4 years ago

@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

matejdubec commented 4 years ago

@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

zite commented 4 years ago

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?

methusalah commented 4 years ago

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

methusalah commented 4 years ago

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

The process:

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

zite commented 4 years ago

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

methusalah commented 4 years ago

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

Great job!

matejdubec commented 4 years ago

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!

kinacho2 commented 4 years ago

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

ary1111 commented 4 years ago

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!