VRDevice.isPresent arrives late to the party

EDIT: Fixed in beta 5.

I want to detect if a Rift is attached and turned on at the program start before any Awake() functions are called so I can do some initialization that depends on whether or not the Rift is present. Before this latest beta I did this with OVRManager.display.isPresent which worked great. Since the new VR stuff is built in to some new classes, I thought I could accomplish the same thing with the new VRDevice.isPresent.

The trouble is that this variable returns false until some considerable time after the play button has been pressed or the built program has started running. If I print the variable in Update()/FixedUpdate() it turns from false to true eventually, but it’s not until a lot of time has passed. Is this something that will be changed eventually so it works similarly to OVRManager.display.isPresent? I’d think the variable really ought to be updated before any Unity functions are called at all. Otherwise I’m going to have a lot of work ahead of me to try and somehow initialize things well after the scene has already loaded. Is there another way? Would it be a bad idea to import the OVRManager script and use that like I did before?

Hey Todd, could you submit a bug report for this and post the case number here on the forum for us to look into. The easiest way (in the meantime) to tell if a device is present is if VR.VRSettings.loadedDevice is not VR.VRDeviceType.None.

Thanks, Ed.

(Case 691201) VRDevice.isPresent is late to the party

I’m not sure if I saved that project correctly before I sent it. If it doesn’t work, drop my Test script onto the camera if it’s not there and click the Virtual Reality Supported option.

Yeah, I had tried this before with no luck. Just tried it again now and it doesn’t really work. If Virtual Reality Supported is checked, VRSettings.loadedDevice == Oculus whether the Rift is present or not. So what I’ve been doing is building it one way or the other depending on what I’m testing.

This was the test:

void Start()
    {
        if (VRSettings.loadedDevice != VRDeviceType.None)
        {
            print("VR device found");
        }
        else
        {
            print("VR device NOT found");
        }
    }

It prints “found” if Virtual Reality Supported is checked, otherwise it’s “not found.” Doesn’t matter if the Rift is there or not.

Hmm. If Virtual Reality is checked, but the HMD is not found at start, it should be reverting to VRDeviceType.None. Can you check if the same thing that is happening with present, is happening here as well? As in, does this value also change at some point later in Update?

Good idea, I didn’t think of that. Will check now.

Nope, it’s different. It returns the same thing right from Start() onwards. It just matches the VR supported option whether the Rift is there or not.

Confirmed fixed in beta 5.

Thanks Todd, Let us know if there are any other delay issues with other VRSettings or if you see this come up again in a future build. We will definitely keep an eye on this though.

Will do, Ed. Thanks for the help and very quick fix.

I’m still having some issues with GUI flickering but will try to deal with that separately in a repro project if I can reproduce it. That’s a story for another thread.