(5.2.1p2) VRDevice.isPresent always return true

It’s all in the title, i guess i have to fill another bug report.
Edit : The error seems random (my test reported ‘false’ only one time)
Edit2 : bug report Case 733411

You’re finding this error too? Happens to me constantly now after the update.

I think I figured it out: The flag is backwards. I turned on “Virtual Reality Supported” in the Player Settings, and it started working.

It seems to work again with patch 3.

in fact it still has the bug, seems random, havn’t tried with patch 4. @Keith-Maggio i’ll try your solution.

I’m still get this with 5.2.2f1 - ideally I don’t want to hack a ‘are you using a VR device screen’ before going into the game proper. Has anyone discovered a work around we can use in the interim?

I have come to the conclusion that VRDevice.isPresent is actually “room wide”. So even though the Oculus runtime is disabled and the Rift is unplugged, Unity knows that the device is still in the same room and so it isPresent and returns true. Very powerful Voodoo indeed. It may be distance related. I should bundle my mother in law into the car with the Rift and get her to drive north and see how far she has to get before it returns false. With any luck she will hit ice before I get a negative :wink:

EDIT: Just updated to Oculus Runtime 0.8 - no change :frowning:

:slight_smile: Guess we just have to wait and see. The bug report is open. 5.2.2f1 is now the recommended version (along with the latest version of oculus utilities) : https://forums.oculus.com/viewtopic.php?t=25882

1 Like

I had the same issue and discovered that OVRManager.isHmdPresent seems to do the trick. This is how I’m using it:

using UnityEngine;

public class StartupDetectVR : MonoBehaviour
{
    public GameObject nonVrCam;
    public GameObject vrCameraRig;

    void Awake()
    {
        if (this.enabled)
        {
            Debug.LogFormat("StartupDetectVR: OVRManager.isHmdPresent={0}", OVRManager.isHmdPresent);
            EnableVR(OVRManager.isHmdPresent);
        }
    }

    void EnableVR(bool isVr)
    {
        nonVrCam.SetActive(!isVr);
        vrCameraRig.SetActive(isVr);
    }
}

Oh, just noticed this in 5.2.2p1 release notes:

  • (732236) - VR: Fix VRDevice.IsPresent always returning true

Haven’t tested it yet though.

1 Like

Don’t work for me in v5.2.2p1, it always returning true.

I use this code to detect VR:

if(VRSettings.loadedDevice != VRDeviceType.None)
{

}
else
{

}

@brzozowsky To tell if the hmd is present use VRDevice.isPresent. Keep in mind the value will always be true if the VRdeviceType is VRDeviceNull though. So you should check the value with VRSettings.loadedDevice to make sure you have the correct device loaded.

Hi Ed, thanks for the heads up with the VRSettings.loadedDevice. Here is what I have, and the results:

void Start () {

string theVRDevice = VRSettings.loadedDevice.ToString();

Debug.Log("The loaded device is: " + theVRDevice);

if (VRDevice.isPresent)
{
Debug.Log(“VR HMD is present.”);
}
else
{
Debug.Log(“NO VR HMD found…”);
}

}

  1. Turn on the Rift and run:
    The loaded device is: Oculus
    VR HMD is present.

  2. Turn the rift off and run:
    The loaded device is: Oculus
    NO VR HMD found…

  3. Stop and run again:
    The loaded device is: None
    VR HMD is present.

(3 is repeated with each subsequent run whilst the headset turned off. Turn it back on again and the cycle repeats.)

Soooo - tweaking the if statement to:

if (VRDevice.isPresent && VRSettings.loadedDevice.ToString() != “None”)
{
Debug.Log(“VR HMD is present.”);
}
else
{
Debug.Log(“NO VR HMD found…”);
}

Gives me the correct result every time. Well that’s me happy :smile:

@Lupus_Solus Yeah, that is a good solution. I’m also going to be fixing VRDeviceNull to return false for IsPresent that way there is less confusion here. I’ll also have to look into why the first time you run after you remove the HMD it stays as Oculus. Thanks for pointing that out.