,I've the problem, that my app made with unity for Oculus Quest2 does'nt stop and resume, when I take off the VR-glasses. What am I missing? What do I need to set-?

I’ve the problem, that my app made with unity for Oculus Quest2 does’nt stop and resume, when I take off the VR-glasses. What am I missing? What do I need to set?

It depends if you use new or old way with plugins and/or Oculus Integration unitypackage. Remember that no audio or input other than to unpause should be possible. You need to do the actual pause your self. This works for me (in my GameManager that always runs)…

using UnityEngine.XR;
using Oculus.Platform;

bool bPause = false;
void Update()
{
    //get user present this way
    UnityEngine.XR.InputDevice headDevice = InputDevices.GetDeviceAtXRNode(XRNode.Head);
    bool presenceFeatureSupported = headDevice.TryGetFeatureValue(
        UnityEngine.XR.CommonUsages.userPresence, out bool userPresent);

    //also pause if in oculus home universal menu
    bool bPauseNow = (!OVRPlugin.hasInputFocus || !OVRPlugin.hasVrFocus) || !userPresent);

    //pause state change
    if (bPause != bPauseNow)
    {
        bPause = bPauseNow;
        if (bPauseNow)
        {
            Time.timeScale = 0.0f; //stops FixedUpdate
            AudioListener.pause = true; //also need to stop all sound
        }
        else
        {
            Time.timeScale = 1.0f;
            AudioListener.pause = false;
        }
    }
    if(bPause) return; //prevent other input from below
    
    //...
}

Thank you very much, @rh_galaxy. I am using Oculus integration unitypackage. Unfortunately your code is not working. Or maybe I copied it into the script wrong?

I used it in this way:

public class XRDevice
{
private static InputDevice headDevice;
public XRDevice() {
if (headDevice == null)
{
headDevice = InputDevices.GetDeviceAtXRNode(XRNode.Head);
}
}

/// <summary>
/// returns true if the HMD is mounted on the users head. Returns false if the current headset does not support this feature or if the HMD is not mounted.
/// </summary>
/// <returns></returns>
public static bool IsHMDMounted()
{
    if(headDevice == null || headDevice.isValid == false)
    {
        headDevice = InputDevices.GetDeviceAtXRNode(XRNode.Head); 
    }
    if (headDevice != null)
    {
        bool presenceFeatureSupported = headDevice.TryGetFeatureValue(CommonUsages.userPresence, out bool userPresent);
        if (headDevice.isValid && presenceFeatureSupported)
        {
            return userPresent;
        }
        else
        {
            return false;
        }
    } else
    {
        return false;
    }
}

}