,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?
Answer by Spherea3D · May 26 at 08:40 AM
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;
}
}
}
Is it compiling? What version of Unity do you use? But if you use Oculus.Platform maybe you can use this?
OVRPlugin.userPresent
Sorry, but I'm quite newbe. How can I use OVRPlugin.userPresent? I'm using Unity 21.2.18 It is still compiling... Thanks!
By adding this at the top of the file...
using Oculus.Platform;
That is available since you say you use Oculus integration.
Answer by rh_galaxy · May 25 at 06:53 PM
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
//...
}
Your answer

Follow this Question
Related Questions
how to get component of array in unity 0 Answers
"Failed to load window layout" Error 5 Answers
Unity installation error, DISM 87 0 Answers
3D grid tetris game problem! 0 Answers