cancel
Showing results for 
Search instead for 
Did you mean: 

Correct way to pause game when headset removed / Dash up?

PicoPlanetDev
Level 4
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:
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:
eeppez5i2x4a.png

Any help / code would be greatly appreciated!
5 REPLIES 5

rh_galaxy
Level 7
I 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;
}
}


PicoPlanetDev
Level 4
Ok, @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)

PicoPlanetDev
Level 4
Alright, 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_galaxy
Level 7
I think that's ok, and that the AudioListener.pause does the rest, but please try it more to be sure.

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!