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

    sh0v0r
    sh0v0rAuthor
    Up and Coming
    June 14, 2013
    OK, just did some testing and it turns out that if there is an OVRCameraController enabled in the scene it will return true. If I disable it, then it returns false. What I want to do is check if the hardware is present regardless of there being a controller in the scene. That way I can enable the controller if the hardware is detected and chose the correct code path.
    sh0v0r
    sh0v0rAuthor
    Up and Coming
    June 14, 2013
    Well on further inspection I realised the error of my ways, disabling the OVRCameraController disables the OVRDevice component.

    So what I have done is created an 'Enabled' empty GameObject with just the OVRDevice Component and removed the OVRDevice Component from the 'Disabled' OVRCameraController.

    Then in Start() I do this:

         
    if (OVRDevice.SensorCount > 0)
    {
    normalCamera.SetActive(false);

    riftCamera.SetActive(true); // OVRCameraController
    }


    I tested this works by pulling the USB cable out and restarting it and vice versa.
    Up and Coming
    June 14, 2013
    Awesome. Thanks for posting your outcome with this.
    Riftmax Theater 4D Multiplayer VR Cinema! http://www.riftmax.com - Latest DK2-ready version 0.415(11/27/2014)
    Inspiring
    June 14, 2013
    Thanks for sharing the solution.
    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
    Up and Coming
    June 13, 2014
    OVRDevice.SensorCount doesn't seem to exist anymore in 0.3.2, but OVRDevice.IsSensorPresent() works for me!
    BLACKISH (Games) | GameAssets.net (Assets)
    Up and Coming
    June 13, 2014
    Good to know. Thanks for sharing sh0v0r and Blackish!
    Inspiring
    June 13, 2014
    Just checked on this for clarity:

    OVRDevice.IsHMDPresent() tells you whether the DVI/HDMI cable is connected/recognized between the control box and the PC. Didn't check if it's hot-swappable.

    OVRDevice.IsSensorPresent() tells you whether the USB cable is connected between the control box and the PC. Seems to be hot-swappable.

    If you're able to toggle between Rift mode and monitor mode on the fly, the logic could be simply "any time either HMD or Sensor is not present, revert to standard monitor mode".

    Warning: It does not appear you can rely on these values returning the correct value until after Awake()/Start(). Either fiddle with script execution order, or put your Rift-detection logic in Update().
    Titans of Space PLUS for Quest is now available on DrashVR.com
    New Participant
    July 9, 2014
    Thanks for the info guys.

    I confirm that OVRDevice.IsSensorPresent() is hot-swappable while OVRDevice.IsHMDPresent() is not!
    New Participant
    July 30, 2014
    I'm starting to integrate the Oculus Rift to a simple scene in unity.
    I have two cameras in the scene, one is the main camera from Unity and the second one is the camera controller of the Oculus rift. I detach the OVRDevice script from the camera controller but the behavior hasn't change. If the empty object that contains the OVRDevice script is enabled, the OVRDevice.IsSensorPresent() will always return true. The same happens with the IsHMDPresent(). I'm using the DK1 with the 0.4 SDK, I don't know if that has something to do with it.
    Is there any other way to detect the actual hardware device?
    Up and Coming
    July 30, 2014
    "blank0" wrote:
    I'm starting to integrate the Oculus Rift to a simple scene in unity.
    I have two cameras in the scene, one is the main camera from Unity and the second one is the camera controller of the Oculus rift. I detach the OVRDevice script from the camera controller but the behavior hasn't change. If the empty object that contains the OVRDevice script is enabled, the OVRDevice.IsSensorPresent() will always return true. The same happens with the IsHMDPresent(). I'm using the DK1 with the 0.4 SDK, I don't know if that has something to do with it.
    Is there any other way to detect the actual hardware device?


    I noted the same issue in my post here: https://developer.oculusvr.com/forums/viewtopic.php?f=37&t=10892#p143830

    Warning: It does not appear you can rely on these values returning the correct value until after Awake()/Start(). Either fiddle with script execution order, or put your Rift-detection logic in Update().


    drash might be right here, it's possible they've recently changed this behaviour in 0.4. I'm calling IsHMDPresent() in the exact same place where it worked in 0.2 and 0.3, and it doesn't seem to be working correctly in 0.4 - but I'll see if delaying the check makes any difference.

    Edit: IsHMDPresent(), IsSensorPresent() and IsCameraPresent() do appear to be returning true regardless of the device state even with OVRDevice earlier in execution order and/or in an Update loop. I think this is just an issue with 0.4.
    VisiR - Virtual Reality Music Visualisation