ValveSoftware / openvr

OpenVR SDK
http://steamvr.com
BSD 3-Clause "New" or "Revised" License
6.07k stars 1.28k forks source link

No way to listen to Oculus Rift "Oculus" button (right hand) - or losing app focus? #1163

Open plmayer opened 5 years ago

plmayer commented 5 years ago

On the Vive controllers and the Windows Mixed Reality controllers, listening to SteamVR_Events.InputFocus yields a call whenever the system buttons on these controllers are pressed.

However, this is not the case for the Oculus Rift: A button press on the Oculus System button does not lead to an InputFocus event. Instead, I get InputFocus events when the user presses the menu button (which leads to the SteamVR system menu) or takes off the headset (or puts it on again) (although the latter doesn't seem to be very consistent).

So, is there any other way to be notified when the user presses the system button on an Oculus Rift? Specifically, I would like to pause and unpause my game whenever the user enters the (Oculus!) system menu or returns. Thanks.

plmayer commented 5 years ago

I talked to Unity about this issue and they have no workaround, it seems it is not possible do either a) be informed when the button is pressed or b) be informed when the focus is lost from the game (in VR).

This is rather unfortunate because it prevents pausing the game when the Oculus button is pressed on OpenVR. Is there really no solution for this?

JoeLudwig commented 5 years ago

Oculus doesn't expose that button, so SteamVR doesn't have access either. That's not the right way to test for overlays and other system UI in any case. You could easily get out of sync and end up pausing at exactly the wrong times.

I don't know how it's plumbed into the Unity plugin, but the C++ API has an IVRSystem::ShouldApplicationPause function that returns true when the application should pause. That should be wired up to the Oculus overlay session state and should start returning true when the application should pause. Is that not working for you?

plmayer commented 5 years ago

That's not the right way to test for overlays and other system UI in any case.

If you mean that it is preferable to have a platform event for "focus lost/gained" instead of listening to the buttons yourself, then I completely agree. There just didn't seem to be a way to do that, which led me on a goose-chase for the buttons.

Having said that, while the IVRSystem::ShouldApplicationPause method is not exposed as part of the Unity framework itself (I've opened a bug for that with them, they've acknowledged the problem) and it is not part of the standard Unity OpenVR plug-in event system either, it is exposed via the OpenVR C++ bridge classes, and indeed does indicate the loss of focus for the Rift both for the app menu and the Oculus buttons. So, yes, that's (now) working for me - thanks very much for the heads-up on that function!

By the way: The Oculus SDK provides access to the proximity sensor via OVRPlugin.userPresent, where loss of user presence is also a pause situation. Taking off the headset, however, does NOT trigger IVRSystem::ShouldApplicationPause. Is this exposed in OpenVR in another way?