I can only try and give you a guess, but my idea would be that display.isPresent and tracker.isPresent get initialized and set to true after the Start() finishes.
So when you call Start, it checks the Ovr.hmd.detect which could just be if a rift is indeed connected (which it is in your case), but then goes to initialize the display and tracker, and even if that initialization takes a millisecond more than the Start frame, your second “if” will never become true. To check if that’s indeed the reason, you can try doing something like:
Haven’t tested this but the idea is to hang inside a while until both bools become true, if this will ever print “Both display.isPresent and tracker.isPresent = true” to your console that means that, as I suggested, the Rift initializations for display and tracker are not done to be ready “on start”.
IF that’s the case, then you could easily go and make sure all your scripts are synchronized to accomodate for that time offset needed to initialize tracker and display.ispresent.
public IEnumerator MoreOculusChecks()
{
while ( !OVRManager.display.isPresent && !OVRManager.tracker.isPresent )
{
Debug.Log ( "Still not detected" );
}
Debug.Log( "Both display.isPresent and tracker.isPresent are now true!" );
}
This was the error message: error CS0161: `myScript.MoreOculusChecks()': not all code paths return a value
I added a line to address this, based on what I learned about this err msg. Not too sure if this is the best way though. Also, not sure if this method should be static as well?
public IEnumerator MoreOculusChecks()
{
while ( !OVRManager.display.isPresent && !OVRManager.tracker.isPresent )
{
Debug.Log ( "Still not detected" );
}
Debug.Log( "Both display.isPresent and tracker.isPresent are now true!" );
yield return null;
}
But I still only get the msg from Ovr.Hmd.Detect() in the console.
I am working on it, but please do indulge me with your ideas…
bool displaytracker_initialized;
bool MoreOculusChecks()
{
if ( !OVRManager.display.isPresent && !OVRManager.tracker.isPresent )
{
Debug.Log("still not detected");
return false;
}
else
{
Debug.Log( "Both display.isPresent and tracker.isPresent are now true!" );
return true;
}
}
And then, inside your Update(), put this somewhere:
displaytracker_initialized = MoreOculusChecks();
this will run the check every frame and will additionally give you a variable (displaytracker_initialized) that is either true or false based on the result of the check
Versions earlier than the patch version 5.2.2p1 also have this functionality but it is broken and always returns true. In this case, if you do not want to install a patch you can use:
If you are using either of the devices then both of these options will tell you whether one is connected.
If you are trying to distinguish which device is being used between the two of them then you could first check whether your build target is Android or desktop and then use the previously mentioned enum checks.
VRSettings.loadedDevice returns as VRDeviceType.Oculus for both GearVR and Oculus but if you’ve checked which build target you’re aiming for then you’ll know which device is connected.
With the new (now official; ONLY supported; XR toolkit) … isPresent appears to be broken in Unity 2019.x (all versions through to 2019.3.3).
XRSettings.isPresent == always returns false, no matter what
XRSettings.isDeviceActive == correctly returns true when VR headset is plugged in and live.