Forum Discussion
PicoPlanetDev
5 years agoProtege
Correct way to pause game when headset removed / Dash up?
Hi! I am working on a VR application and I need to meet VR.PC.Functional.3. I am testing this in a simple Menu Scene I designed, and it only works partially. When I hit the Oculus button to return to the Dash, the app pauses. Hitting that button again returns the game correctly. However, upon removal of the headset and putting it back on, the OVRCameraRig never begins rendering again. I looked at the component in the inspector while this problem is occurring, and it appears the the OVRCameraRig never was SetActive(true) again. Can anyone help or give me their code that works?
Thanks in advance,
PicoPlanet Developing
Below is my pause script, attached to a separate gameobject:
Any help / code would be greatly appreciated!
Thanks in advance,
PicoPlanet Developing
Below is my pause script, attached to a separate gameobject:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MenuPauseControl : MonoBehaviour
{
public GameObject OVRCameraRig;
public GameObject Canvas;
public GameObject EventSystem;
void Start()
{
}
void Update()
{
if (OVRManager.hasInputFocus && OVRManager.hasVrFocus)
{
ContinueGame();
}
else
{
PauseGame();
}
}
private void PauseGame()
{
Time.timeScale = 0;
//Disable stuff that still work while timescale is set to 0
OVRCameraRig.SetActive(false);
Canvas.SetActive(false);
EventSystem.SetActive(false);
}
private void ContinueGame()
{
Time.timeScale = 1;
//enable the stuff again
OVRCameraRig.SetActive(true);
Canvas.SetActive(true);
EventSystem.SetActive(true);
}
}and here's my hierarchy:Any help / code would be greatly appreciated!
6 Replies
Replies have been turned off for this discussion
- rh_galaxyHeroic ExplorerI don't think you should do "OVRCameraRig.SetActive(false);"
I have this in my GameManager Update()...//pause if in oculus home universal menu, and if headset not worn
bool bPauseNow = (!OVRManager.hasInputFocus || !OVRManager.hasVrFocus) /*|| (XRDevice.userPresence!=UserPresenceState.Present)*/;
//pause state change
if (bPause != bPauseNow)
{
bPause = bPauseNow;
if (bPauseNow)
{
Time.timeScale = 0.0f; //stops FixedUpdate
//also need to stop all sound
AudioListener.pause = true;
AudioStateMachine.instance.masterVolume = 0.0f;
}
else
{
Time.timeScale = 1.0f;
AudioListener.pause = false;
AudioStateMachine.instance.masterVolume = 1.35f;
}
}- victoriascottHonored Guest
Hi rh_galaxy,
I'm also failing my VR.PC.Functional.3, VR.PC.Input.2 & VR.PC.Input.3 and Oculus tech pointed me to this page.Your code looks great, however, I am new to State Machines.
How are you declaring bPause and AudioStateMachine? Are these ints or floats? Public or Private?
Thanks so much!
- PicoPlanetDevProtegeOk, @rh_galaxy ! Thanks for your help! I will test this code out right away and let you know how it works. Jast a question - do you need to define the audio listeners to turn off or does that AudioListen.pause cover any audio listener in the scene?
Thanks for your help!
Sig (PicoPlanetDev) - PicoPlanetDevProtegeAlright, I tried it out - it seems to work because no sound happens if I hit where a drum is and physics seems to be stopped by the timescale = 0, but I did notice that when the headset is taken off / dash open, more frames are still being submitted. Is that OK?
Thank you! - rh_galaxyHeroic ExplorerI think that's ok, and that the AudioListener.pause does the rest, but please try it more to be sure.
- OsmanGhaziHonored Guest
Hi everyone, i ran into the same problem, to pause my game when user removes headset for his /her head.
After trying alot of thing i finnaly got it working like i wanted by adding my code to a certain place in update function in the OVR Manager script
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 3 years ago
- 8 months ago