Showing results for 
Search instead for 
Did you mean: 

OnHead Detection Sensor

Level 2
Hello Guys, I'm developping for Gear VR on Unity3D

The Gear VR detect when you but the Oculus on the Head, using the distance detection sensor.

I want to put some functions when the user put on or take of the head of the display.
Where can I find the functions that control this features ?

I'm searching on OVRScripts on C# but I dont found the class that turn off or turn on the display.

Level 2
We provide an interface to native applications to detect when the user mounts/unmounts the headset (ovr_HeadsetIsMounted). We will try to make this available to Unity applications as well.

Level 2
I'm desperately needing the same ability to read proximity of GearVR in Unity. Since it's been a month since the last post, is there any updated timing info for the implementation of this? Seems like a very important and basic event many Unity apps/games could use.

update - Going to try to build a native plugin to test for removal. If anybody already has one built or started please share. /me launches self into the void...

Level 2
Here is my 'progress' so far...

I installed Android Studio and latest OVR Mobile SDK.

I found ovr_HeadsetIsMounted(); inside of VrApi_Android.h in the OVR Mobile SDK so know it exists and is supposed to return a bool value (see bottom of code chunk):

excerpt from VrApi_Android.h
// Device Feature Support
// These can be called any time from any thread.

OVR_VRAPI_EXPORT int ovr_GetSystemProperty( const ovrJava * java, const ovrSystemProperty prop );

// Device Status
// Note that there is currently no way to tell what the initial dock/mount state
// is when the vrapi_Initialize() is first called. Only when the state changes after
// vrapi_Initialize() has been called we can tell what the real state is. To work
// around this problem, we assume the device is docked and the headset is mounted
// when we enter VR mode, and no dock/mount state changes have been recorded up
// to that point. Under normal circumstances this is usually correct. This is
// incorrect when in developer mode, but in that case you want the device to
// appear as docked and the headset as mounted anyway.
// These can be called any time from any thread.

// Can be used to detect when the device is docked/undocked.
OVR_VRAPI_EXPORT bool ovr_DeviceIsDocked();

// Can be used to detect when the device is mounted/unmounted.
OVR_VRAPI_EXPORT bool ovr_HeadsetIsMounted();

I created a new Android Studio project for the plugin and imported the VrApi.jar as a library.

I looked through the VrApi.jar files and can't find ovr_HeadsetIsMounted(); anywhere in them- maybe that's OK.

Can someone help take me through the finish line by telling me how to poll ovr_HeadsetIsMounted(); from Java? Hoping this is super simple, I have only used Unity/C# for GearVr before today so it's all new.

Level 15
The ovr_HeadsetIsMounted() is used from native code and doesn't work in Java. However, I am unsure if that function will give you what you need and may not be reliable.
AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV

Level 2
Thank you for the response!

I'm installing the Android NDK: and will try it out today. If I can get a native code plugin working or partially working I'll post code up here for anyone following this thread.

Level 2
After a week of hair pulling I finally managed to setup my environment for native development, created a functional native .so plugin, successfully communicated with it from C# inside Unity, and attempted to poll the ovr_HeadsetIsMounted method via native code in the plugin.

For whatever reason ovr_HeadsetIsMounted always returns a FALSE value, no matter physical headset position. So unless I missed something in the code, this method seems unreliable as cybereality suggested.

If anybody has run into this issue and knows a fix I'll buy you a beer. In the meantime I'll continue poking around. It may have something to do with how the Oculus libs are being built since compiling also builds a sidecar file that I put in the Android plugins alongside my .so. Maybe they are not talking together at that point and I need to completely wrap inside my .so somehow- prob in the file somewhere if that's it...

Note - I got no build errors via terminal ndk-build or unity build, and a fake random bool generator worked fine in the same plugin so I know Unity<>my .so communication works fine.

Level 2
I don't know if it can help in Unity but in Java you can detect the headset position by intercepting an intent.

protected void onResume() {
IntentFilter intentFilter = new IntentFilter(
mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {

Log.v(LOGTAG,"headset mounted");
Log.v(LOGTAG,"headset unmounted");

this.registerReceiver(mReceiver, intentFilter);

protected void onPause() {

You have to add an intent filter in the manifest :

<action android:name="android.intent.action.proximity_sensor" />

Level 2
Any updates on this capability being exposed in Unity?

Not applicable
 Any updates on this for Android with Studio? ref