ViveSoftware / ViveInputUtility-Unity

A toolkit that helps developing/prototyping VR apps.
http://u3d.as/uF7
Other
357 stars 82 forks source link

VRModule.GetDeviceState(0).deviceModel is returning Unknown with an Oculus Rift headset #121

Closed wirelessdreamer closed 4 years ago

wirelessdreamer commented 5 years ago

VRModule.GetDeviceState(0).deviceModel is returning Unknown with an Oculus Rift headset

Expected result is returning: VRModuleDeviceModel.OculusHMD

chengnay commented 5 years ago

Do you have any SDK(Oculus SDK or others) imported? Or are you using UnityEngine? If yes, please list the version, thanks!

chengnay commented 5 years ago

@wirelessdreamer I just tried over my side with Clean project(Unity 2019.2.0a9) with Oculus SDK(0.0.0) imported. I can query the deviceModel with the API you used. I might need more information to duplicate the issue.

chengnay commented 5 years ago

@wirelessdreamer If you can duplicate on your project, could you help to debug in below function,

  1. In VRModule.cs, line 133 public static IVRModuleDeviceState GetCurrentDeviceState(uint deviceIndex) { if (!IsValidDeviceIndex(deviceIndex) || Instance == null || Instance.m_currStates == null) { return s_defaultState; } return Instance.m_currStates[deviceIndex] ?? s_defaultState; }

Print debug message in this function, check which s_defaultState does it return.

wirelessdreamer commented 5 years ago

This is what I see for Device State: HTC.UnityPlugin.VRModuleManagement.VRModule+DeviceState

Here is a clean project that reproduces the behavior:

https://mega.nz/#!hstAiCIb!3LAqYTRij95zd-2jqaY4Mids5-oRG1JyUitNOn0ZRN8

BodyRole.cs and BindingInterfaceRolePanelController.cs have both been modified. On project start BindingInterfaceRolePanelController will output the device state and model it sees.

image

I see the same behavior with both a Vive Pro, and Rift CV1

chengnay commented 5 years ago

@wirelessdreamer Do you get Unknown device model non-stop or just ~30 times after you start playing? At the very beginning when Unity starts playing, the index 0 will be an invalid index. That's why you will get Unknown for device model. You can try below code to avoid getting invalid index.

if (VRModule.IsValidDeviceIndex(VRModule.HMD_DEVICE_INDEX)) { switch (VRModule.GetDeviceState(VRModule.HMD_DEVICE_INDEX).deviceModel) { case VRModuleDeviceModel.OculusHMD: //... Debug.Log("Device Model: " + VRModule.GetDeviceState(0).deviceModel.ToString()); break; } }

wirelessdreamer commented 5 years ago

A valid device was never returned in the example above. I hadn't enabled XR support in the uploaded one, but once you enable it in that project the headset works fine, but always says unknown

chengnay commented 5 years ago

I enabled the XR Settings, image The code you added will only trigger when you click on the BodyRole, HandRole and TrackerRole. You launch the RoleBindingExample scene, am I correct?

wirelessdreamer commented 4 years ago

In the current release this works on Rift S, but not in Quest build. Quest builds it returns Unknown still

chengnay commented 4 years ago

@wirelessdreamer Please share your AndroidManifest.xml and also the version for Unity/Oculus SDK/Oculus XR Plugin, thanks!

https://mega.nz/file/hstAiCIb#3LAqYTRij95zd-2jqaY4Mids5-oRG1JyUitNOn0ZRN8

Can I still reproduce your issue using the link above?

wirelessdreamer commented 4 years ago

Unity 2019.4.8.f1 Legacy Oculus XR Plugin Oculus plugin 19.1

I reread your previous post about IsValidDeviceIndex, and using this design pattern, I saw the problem was I assumed it would be available before it was. This is always successfull:

IEnumerator WaitForDeviceIndex() { yield return new WaitUntil(() => VRModule.IsValidDeviceIndex(VRModule.HMD_DEVICE_INDEX)); yield return new WaitForEndOfFrame(); Debug.Log("Headset is: " + VRModule.GetDeviceState(0).deviceModel);
}

Feel free to close this out, though I'd be glad to test or get your more info if its needed.