Skip to main content
sh0v0r
Up and Coming
June 13, 2013

Correct Way To Detect The Hardware

I'm trying to make my game automatically switch to OVR mode when the Hardware is detected but I'm unsure as to how to do that correctly?

I have tried doing this:

if (OVRDevice.IsHMDPresent())


But it seems to be true even when the headset is unplugged, I can only assume that it's because there is an OVRCameraController in the scene, what is the correct way to do this?
    This topic has been closed for replies.

    21 replies

    Inspiring
    July 30, 2014
    "excelynx" wrote:
    IsHMDPresent(), IsSensorPresent() and IsCameraPresent() do appear to be returning true regardless of the device state

    Thanks, there were bugs in the code for IsSensorPresent() and IsCameraPresent(). It's not clear why IsHMDPresent() is always true for you. On my machine, it returns false when I disconnect the USB cable. Do you get the same behavior if you run the native OculusWorldDemo that comes with our C++ SDK?
    Up and Coming
    July 30, 2014
    "vrdaveb" wrote:
    Do you get the same behavior if you run the native OculusWorldDemo that comes with our C++ SDK?


    Nope. If I remove the HMD USB cable the native OculusWorldDemo correctly detects and displays "No HMD Present."

    If you want me to do any more testing, just let me know.
    VisiR - Virtual Reality Music Visualisation
    Inspiring
    July 30, 2014
    That is odd. Can you try the following C# code instead of OVRDevice.IsHMDPresent()?

    var HMD = OVR.Hmd.GetHmd();
    ovrTrackingState ss = HMD.GetTrackingState();
    bool isConnected = (ss.StatusFlags & (uint)ovrStatusBits.ovrStatus_HmdConnected) != 0;
    Up and Coming
    July 30, 2014
    "vrdaveb" wrote:
    That is odd. Can you try the following C# code instead of OVRDevice.IsHMDPresent()?

    var HMD = OVR.Hmd.GetHmd();
    ovrTrackingState ss = HMD.GetTrackingState();
    bool isConnected = (ss.StatusFlags & (uint)ovrStatusBits.ovrStatus_HmdConnected) != 0;


    That snippet works perfectly. :)

    Any ideas why calling that from my code would work and IsHMDPresent() wouldn't?

    Edit: Oh, nevermind, I see the difference.
    VisiR - Virtual Reality Music Visualisation
    New Participant
    November 11, 2014
    I am using the 0.4.3 SDK and am also trying to show the Oculus display if it is connected and the normal camera view if it isn't. I can correctly detect the device by using Ovr.Hmd.Detect().

    The problem I am running into is that I can't disable the OVRCameraRig in Start(). I have tried the following without any success:
    oculusCamera.enabled = false;
    oculusCamera.camera.enabled = false;
    OVRCameraRig.Destroy(oculusCamera);

    I then try to set the other camera with: mainCamera.camera.enabled = true;

    Has anyone found a way to switch to the standard camera with an OVRCameraRig embedded into the scene?
    korinVR
    Honored Contributor
    November 12, 2014
    "mattgraham" wrote:
    Has anyone found a way to switch to the standard camera with an OVRCameraRig embedded into the scene?

    To do that, I create a game object witch has a normal camera as a child. I instantiate a rift camera prefab in it and if Oculus Rift is connected, I disable the normal camera. If not connected, I destroy the prefab instantly.

    The hierarchy and code are below:

    VRCamera
    + Main Camera

    VRCamera
    + (Main Camera)
    + Rift Camera
    --+ OVRCameraRig


    using UnityEngine;

    public class VRCamera : MonoBehaviour
    {
    public Transform riftCameraPrefab;

    void Awake()
    {
    // Instantiate OVRCameraRig to detect Oculus Rift
    Transform riftCamera = (Transform) Instantiate(riftCameraPrefab, transform.position, transform.rotation);
    riftCamera.parent = transform;

    if (OVRManager.display.isPresent) {
    // Disable normal camera if Rift is connected
    transform.Find("Main Camera").gameObject.SetActive(false);
    } else {
    // Destroy OVRCamraRift if Rift is not connected
    DestroyImmediate(riftCamera.gameObject);
    }
    }
    }


    This method seems working, debuggable and can easily support other platforms (such as iOS/Android). But I haven't found a good way to handle the Unity configuration dialog. OVRShimLoader.cs is a bit messy, I feel.
    Katsuomi Kobayashi ( @korinVR ) at FrameSynthesis Inc.
    Up and Coming
    November 12, 2014
    Try this:


    public GameObject nonOVRCam;
    public GameObject ovrRig;
    private bool oculusActive = true;

    void Update () {
    if (oculusActive && !OVRManager.display.isPresent){
    ovrRig.SetActive(false);
    nonOVRCam.SetActive(true);
    }
    if (!oculusActive && OVRManager.display.isPresent){
    nonOVRCam.SetActive(false);
    ovrRig.SetActive(true);
    }
    oculusActive = OVRManager.display.isPresent;
    }


    It's basically what the OVRManager.cs does in it's Update for the HMDAquired and HMDLost event delegates, but you cannot use them as HMDAquired did not get fired when you plug the oculus back in, cause the OVRCameraRig is now disabled.

    Another interesting question is how I can differentiate between DK1 and DK2 now (e.g. for HUD Scaling reasons)? In 0.4.2 there was an HDDType Enumeration which seems to be gone.
    ______________________ mySite www.darkfield-vr.com
    New Participant
    November 12, 2014
    Thanks for the feedback! Podden, that code snippet worked perfectly since I only want to check at startup if a device is attached.
    Up and Coming
    March 7, 2015
    Sorry to dig this one back up, but I am trying to detect the Gear VR on-the-fly and have not had much luck.

    I have an OVRCamera prefab disabled by default and an external script that checks for the device and enables it using Ovr.Hmd.Detect() > 0. I have tried both with the prefab enabled and disabled, and also with device.isPresent.

    It appears to always return true for all checks if the prefab is enabled, and always return false when it's disabled. There is no actual hardware detection happening. Is it just mobile not having the detection or is there a new way to do this?
    New Participant
    November 4, 2015
    Unity now has a built-in way to detect this.

    http://forum.unity3d.com/threads/simply ... st-2368233

    Docs: http://docs.unity3d.com/ScriptReference ... esent.html