Detecting Oculus HMD is removed
While running and with an Oculus HDM attached does anyone know of a way to detect if the user/player has removed the headset? I'm trying to setup a script to trigger rendering on screen instructions to the desktop display and then reload the scene once a new player puts the headset on to restart the experience in a multi user scenario.
Answer by WJRRO · Aug 24, 2016 at 05:17 AM
@delphinius81 Posting your answer from Oculus Dev forums:
"You can register delegates for the HMDMounted and HMDUnmounted events through OVRManager.
OVRManager.HMDMounted += HandleHMDMounted;
OVRManager.HMDUnmounted += HandleHMDUnmounted;
void HandleHMDMounted() {
// Do stuff
}
void HandleHMDUnmounted() {
// Do stuff
}
Before using that event to detect when the player puts the headset on, I suggest checking to see if they're already wearing the headset. If they are, that event won't be fired until they remove the headset and put it back on.
if (OVRPlugin.userPresent)
{
Headset$$anonymous$$ounted();
}
else
{
OVR$$anonymous$$anager.H$$anonymous$$D$$anonymous$$ounted += Headset$$anonymous$$ounted;
}
Answer by Hyperactive · Feb 07, 2018 at 10:27 AM
Yesterday I was working on this issue and figured that HMD mount detection happens in OVRManager here:
if (!_wasHmdPresent && isHmdPresent)
{
try
{
if (HMDAcquired != null)
HMDAcquired();
//Put here code that you want to run when the HMD is mounted.
}`
And then the same goes for removal of the HMD:
if (_wasUserPresent && !isUserPresent)
{
try
{
if (HMDUnmounted != null)
HMDUnmounted();
//Put here code that you want to run when the HMD is unmounted.
}
Answer by CorstiaanMediamonks · Apr 04, 2017 at 09:01 AM
Has anyone succeeded in getting this to actually work?
I've tried this but doesn't do anything. When the HMD is taken off, the screen goes black and Unity app suspends.. I haven't been able to run any code in response.
OVRManager.HMDUnmounted += OnHDUnmounted;
private void OnHDUnmounted() {
VRSettings.enabled = false;
BackToMenu();
}
To get content to continue rendering after you remove the headset you need to enable both run in background in the player settings and inside OVR$$anonymous$$anager set "runInBackground" bool to "true".
Answer by Phildo · Dec 07, 2017 at 03:34 PM
This still does not work for me. See this question: https://answers.unity.com/questions/1439714/unity-oculus-ovr-not-responding-to-removeput-on-he.html
I see the comment saying "enable run in background in player settings and inside OVRManager" - I've done so in Player Settings (and in code), but OVRManager lacks a "runInBackground" property... (see docs here: https://developer3.oculus.com/doc/1.18-unity/class_o_v_r_manager.html )
Your answer
Follow this Question
Related Questions
How can I remove Visual Studio from unity and continue to use MonoDevelop? 1 Answer
Skinning Editor Bones Disappear,Bones disappeared from Sprite Editor after Exiting Unity 4 Answers
Oculus Rift not working with Unity 5? 4 Answers
Help me doing teleportation with oculus touch 1 Answer
I can't access play mode with Oculus 0 Answers