Search Unity

XR: Oculus system button/switch to Oculus home via OpenVR

Discussion in 'AR/VR (XR) Discussion' started by plmx, Jul 28, 2019.

  1. plmx

    plmx

    Joined:
    Sep 10, 2015
    Posts:
    308
    Hi,

    when using the Oculus Rift + Touch via OpenVR, the Menu button (three lines) on the left controller lead to the SteamVR system menu, while the System button (Oculus "O") on the right controller leads to the Oculus system menu.

    My question is this: I understand that since the Oculus button is "reserved", I cannot query its state. However, I would still like to be notified somehow of the fact that the user just left the game and entered the Oculus menu (for pausing the game). Where in the XR API can I register to be notified of this event?

    Philip
     
  2. plmx

    plmx

    Joined:
    Sep 10, 2015
    Posts:
    308
  3. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    I would think you'd be better served by watching the state of the application. If the app enters the background, bring up your pause menu. Not tested, but something like this:
    Code (CSharp):
    1. void OnApplicationFocus(bool hasFocus)
    2. {
    3.     if (! hasFocus) {
    4.         // Do your pause stuff here
    5.     }
    6. }
     
    FlightOfOne and plmx like this.
  4. plmx

    plmx

    Joined:
    Sep 10, 2015
    Posts:
    308
    I agree, and I actually tried to use the SteamVR equivalent of OnApplicationFocus in the past, which is the InputFocus event fired by SteamVR. However, that one is not called for Oculus button, only for the application menu button. However, point taken; I shall try Unity's OnApplicationFocus method as well.
     
    Schneider21 likes this.
  5. StayTalm_Unity

    StayTalm_Unity

    Unity Technologies

    Joined:
    May 3, 2017
    Posts:
    182
    @Schneider21 is correct, and if that doesn't get the job done, ping back, and we can bug it/fix it.
     
    Schneider21 and plmx like this.
  6. plmx

    plmx

    Joined:
    Sep 10, 2015
    Posts:
    308
    @StayTalm_Unity @Schneider21 I'm sorry to report that it doesn't. Neither the Oculus Home nor the Steam Home (three lines, normally App Menu) are reported by OnApplicationFocus - whether on Oculus or OpenVR runtime.

    I've submitted a bug, case 1174547. It would be great if this could be resolved.
     
    Schneider21 likes this.
  7. StayTalm_Unity

    StayTalm_Unity

    Unity Technologies

    Joined:
    May 3, 2017
    Posts:
    182
    :(
    I'll have a look into it, it used to work.
     
    Schneider21 and plmx like this.
  8. plmx

    plmx

    Joined:
    Sep 10, 2015
    Posts:
    308
    Thanks. I happened to have an HTC Cosmos here, where it does not work either (they call it the "Vive button"). This might or might not mean that the Vive is affected too (where, by the way, you can also press the button on the side of the headset which I did not know about before looking this issue up ;-) ). I can check for WMR too if you'd like.

    By the way: The OpenVR "InputFocus" event I talked about above works for the Vive's "Vive button", the Rift "App menu button" which leads to SteamVR via OpenVR, and the Windows Mixed Reality ("Windows button") headsets via OpenVR, but not for the Oculus home button.
     
    Last edited: Aug 6, 2019
  9. plmx

    plmx

    Joined:
    Sep 10, 2015
    Posts:
    308
  10. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Any updates to this issue?
     
    AzurySimon likes this.
  11. AzurySimon

    AzurySimon

    Joined:
    Jul 16, 2018
    Posts:
    38
    Same question here, any news?
    Works on the Quest, but not in Standalone.

    Using:
    - Unity 2019.3.0f6
    - XR Management 3.0.5
    - Oculus XR Plugin 1.3.3
     
  12. BHSPitMonkey

    BHSPitMonkey

    Joined:
    Sep 14, 2016
    Posts:
    10
    It's almost time to celebrate this thread's birthday!

    Any updates on this? It's still a problem as of Unity 2020.1.0b16 and Oculus XR Plugin 1.3.4, and unless there's a workaround this blocks release via the Oculus Store since the game needs to take some actions to pause/mute itself when the system menu is open.
     
  13. Extrys

    Extrys

    Joined:
    Oct 25, 2017
    Posts:
    345
    No news on this?
     
  14. NemesisWarlock

    NemesisWarlock

    Joined:
    Jan 21, 2017
    Posts:
    140
    If you're using OVRmanager/direct Oculus stuff, take a look here:
    https://developer.oculus.com/documentation/unity/unity-dash/

    "To check if your app has focus input, query OVRManager.hasInputFocus every frame. If your app has focus hasInputFocus will return true. If the user’s focus is elsewhere, like when the user opens the Dash menu or removes their HMD, hasInputFocus will return false."
     
  15. ReallyJonatanCrafoord

    ReallyJonatanCrafoord

    Joined:
    Jun 30, 2011
    Posts:
    5
    I'm having the same problem as everyone else in this thread, in Unity 2020.3 LTS. We need to detect if user opens Oculus Dash when they are running a SteamVR game so we can pause. OVRManager.hasInputFocus however always returns false if you're using SteamVR, even with an Oculus headset connected that clearly has focus. Has anyone managed to solve this?

    @StayTalm_Unity said they'd look into why Application.isFocused is not working for VR a year ago, any luck?
     
    Last edited: Sep 14, 2021
  16. BinariJames

    BinariJames

    Joined:
    Mar 21, 2021
    Posts:
    2
    Still have not found a way of detecting the SteamVR menu or Oculus Dash in a SteamVR build (using XR Input system with OpenVR plugin). Any news on this?
     
  17. Dark-Table

    Dark-Table

    Joined:
    Nov 25, 2008
    Posts:
    315
    If you're using SteamVR I'm assuming you've got the SteamVR_Input plugin installed as well? If so in the
    Valve.VR
    namespace there's an event (referenced above, two years ago):

    Code (CSharp):
    1. SteamVR_Events.InputFocus.AddListener(/*Your method here*/);
    If you subscribe to this your method will get called when you press the "pause" button and bring up the SteamVR overlay. I still haven't found a way to detect that the Oculus button has been pressed while in a SteamVR app though.
     
  18. brazzoni

    brazzoni

    Joined:
    Sep 2, 2021
    Posts:
    13
    This is still a probably in 2022 unfortunately. Was running in the editor with this chunk

    private void OnApplicationPause(bool pause)
    {
    isPaused = pause;
    Debug.Log($"OnApplicationPause {pause}");
    }

    Nothing is logged when the button with the Oculus logo gets pressed. Even more strange, if you unfocus from the editor (click any other window) this gets logged:

    OnApplicationPause True


    However, re-focusing on the editor doesn't result in any output, so from the Engines perspective, the app is paused without ever un-pausing. This doesn't break the engine at all, the game still works fine when you refocus. It's just weird.


    The behaviour might be different when you build and use the app standalone. I don't know exactly what the stack trace/call sequence looks like when this happens, but I know that the code I tried does not function in the editor, nor does it visually do what I intended it to do in standalone.
     
  19. brazzoni

    brazzoni

    Joined:
    Sep 2, 2021
    Posts:
    13
    The results I got from my previous reply were a side effect of another bug in my app. Somewhere a long the way my app was configured to not run in the background. OnApplicationPause seems to be un useful on the Quest, but OnApplicationFocus is reliable. Everytime I opened the Oculus Universal Menu, OnApplicationFocus gets called with "false", and as soon as I exit it gets called with "true".


    The bug that broke this behaviour was runInBackground. If runInbackground is 0 (so don't run in background) the app will totally halt, and OnApplicationFocus is never called. You need to manually changed it in "ProjectSettings.asset" which is in projectRoot/ProjectSettings/ProjectSettings.Asset

    runInBackground was roughly on line 79. I changed it from 0 to 1

    I tried changing the Standalone settings in Edit > Project Settings > Player > Resolution, but this didn't change the behaviour. It's a hidden setting for android, so I never changed it, yet something in the unity editor automatically changed to it 0.