Search Unity

(5.2.1p2) VRDevice.isPresent always return true

Discussion in 'AR/VR (XR) Discussion' started by Gruguir, Oct 4, 2015.

  1. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    340
    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
     
    Last edited: Oct 4, 2015
  2. Keith-Maggio

    Keith-Maggio

    Joined:
    Oct 15, 2015
    Posts:
    2
    You're finding this error too? Happens to me constantly now after the update.
     
  3. Keith-Maggio

    Keith-Maggio

    Joined:
    Oct 15, 2015
    Posts:
    2
    I think I figured it out: The flag is backwards. I turned on "Virtual Reality Supported" in the Player Settings, and it started working.
     
  4. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    340
    It seems to work again with patch 3.
     
  5. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    340
    in fact it still has the bug, seems random, havn't tried with patch 4. @Keith Maggio i'll try your solution.
     
  6. Lupus_Solus

    Lupus_Solus

    Joined:
    Jul 14, 2013
    Posts:
    7
    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 ;)

    EDIT: Just updated to Oculus Runtime 0.8 - no change :(
     
    Last edited: Oct 22, 2015
  7. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    340
    Lupus_Solus likes this.
  8. Aranda

    Aranda

    Joined:
    Jan 23, 2015
    Posts:
    16
    I had the same issue and discovered that `OVRManager.isHmdPresent` seems to do the trick. This is how I'm using it:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class StartupDetectVR : MonoBehaviour
    4. {
    5.     public GameObject nonVrCam;
    6.     public GameObject vrCameraRig;
    7.  
    8.     void Awake()
    9.     {
    10.         if (this.enabled)
    11.         {
    12.             Debug.LogFormat("StartupDetectVR: OVRManager.isHmdPresent={0}", OVRManager.isHmdPresent);
    13.             EnableVR(OVRManager.isHmdPresent);
    14.         }
    15.     }
    16.  
    17.     void EnableVR(bool isVr)
    18.     {
    19.         nonVrCam.SetActive(!isVr);
    20.         vrCameraRig.SetActive(isVr);
    21.     }
    22. }
     
  9. Aranda

    Aranda

    Joined:
    Jan 23, 2015
    Posts:
    16
    Oh, just noticed this in 5.2.2p1 release notes:
    • (732236) - VR: Fix VRDevice.IsPresent always returning true
    Haven't tested it yet though.
     
    Gruguir likes this.
  10. brzozowsky

    brzozowsky

    Joined:
    Sep 12, 2011
    Posts:
    39
    Don't work for me in v5.2.2p1, it always returning true.

    I use this code to detect VR:
    Code (JavaScript):
    1. if(VRSettings.loadedDevice != VRDeviceType.None)
    2. {
    3.  
    4. }
    5. else
    6. {
    7.  
    8. }
     
  11. EdBlais

    EdBlais

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    311
    @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.
     
  12. Lupus_Solus

    Lupus_Solus

    Joined:
    Jul 14, 2013
    Posts:
    7
    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 :D
     
  13. EdBlais

    EdBlais

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    311
    @Ladiplace 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.