Forum Discussion
sh0v0r
13 years agoProtege
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:
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?
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?
21 Replies
Replies have been turned off for this discussion
- vrdavebOculus Staff
"excelynx" wrote:
IsHMDPresent(), IsSensorPresent() and IsCameraPresent() do appear to be returning true regardless of the device state
Thanks, there were bugs in the code for IsSensorPresent() and IsCameraPresent(). It's not clear why IsHMDPresent() is always true for you. On my machine, it returns false when I disconnect the USB cable. Do you get the same behavior if you run the native OculusWorldDemo that comes with our C++ SDK? - excelynxHonored Guest
"vrdaveb" wrote:
Do you get the same behavior if you run the native OculusWorldDemo that comes with our C++ SDK?
Nope. If I remove the HMD USB cable the native OculusWorldDemo correctly detects and displays "No HMD Present."
If you want me to do any more testing, just let me know. - vrdavebOculus StaffThat is odd. Can you try the following C# code instead of OVRDevice.IsHMDPresent()?
var HMD = OVR.Hmd.GetHmd();
ovrTrackingState ss = HMD.GetTrackingState();
bool isConnected = (ss.StatusFlags & (uint)ovrStatusBits.ovrStatus_HmdConnected) != 0; - excelynxHonored Guest
"vrdaveb" wrote:
That is odd. Can you try the following C# code instead of OVRDevice.IsHMDPresent()?
var HMD = OVR.Hmd.GetHmd();
ovrTrackingState ss = HMD.GetTrackingState();
bool isConnected = (ss.StatusFlags & (uint)ovrStatusBits.ovrStatus_HmdConnected) != 0;
That snippet works perfectly. :)
Any ideas why calling that from my code would work and IsHMDPresent() wouldn't?
Edit: Oh, nevermind, I see the difference. - mattgrahamHonored GuestI am using the 0.4.3 SDK and am also trying to show the Oculus display if it is connected and the normal camera view if it isn't. I can correctly detect the device by using Ovr.Hmd.Detect().
The problem I am running into is that I can't disable the OVRCameraRig in Start(). I have tried the following without any success:
oculusCamera.enabled = false;
oculusCamera.camera.enabled = false;
OVRCameraRig.Destroy(oculusCamera);
I then try to set the other camera with: mainCamera.camera.enabled = true;
Has anyone found a way to switch to the standard camera with an OVRCameraRig embedded into the scene? - korinVRExpert Protege
"mattgraham" wrote:
Has anyone found a way to switch to the standard camera with an OVRCameraRig embedded into the scene?
To do that, I create a game object witch has a normal camera as a child. I instantiate a rift camera prefab in it and if Oculus Rift is connected, I disable the normal camera. If not connected, I destroy the prefab instantly.
The hierarchy and code are below:
VRCamera
+ Main Camera
VRCamera
+ (Main Camera)
+ Rift Camera
--+ OVRCameraRig
using UnityEngine;
public class VRCamera : MonoBehaviour
{
public Transform riftCameraPrefab;
void Awake()
{
// Instantiate OVRCameraRig to detect Oculus Rift
Transform riftCamera = (Transform) Instantiate(riftCameraPrefab, transform.position, transform.rotation);
riftCamera.parent = transform;
if (OVRManager.display.isPresent) {
// Disable normal camera if Rift is connected
transform.Find("Main Camera").gameObject.SetActive(false);
} else {
// Destroy OVRCamraRift if Rift is not connected
DestroyImmediate(riftCamera.gameObject);
}
}
}
This method seems working, debuggable and can easily support other platforms (such as iOS/Android). But I haven't found a good way to handle the Unity configuration dialog. OVRShimLoader.cs is a bit messy, I feel. - PoddenProtegeTry this:
public GameObject nonOVRCam;
public GameObject ovrRig;
private bool oculusActive = true;
void Update () {
if (oculusActive && !OVRManager.display.isPresent){
ovrRig.SetActive(false);
nonOVRCam.SetActive(true);
}
if (!oculusActive && OVRManager.display.isPresent){
nonOVRCam.SetActive(false);
ovrRig.SetActive(true);
}
oculusActive = OVRManager.display.isPresent;
}
It's basically what the OVRManager.cs does in it's Update for the HMDAquired and HMDLost event delegates, but you cannot use them as HMDAquired did not get fired when you plug the oculus back in, cause the OVRCameraRig is now disabled.
Another interesting question is how I can differentiate between DK1 and DK2 now (e.g. for HUD Scaling reasons)? In 0.4.2 there was an HDDType Enumeration which seems to be gone. - mattgrahamHonored GuestThanks for the feedback! Podden, that code snippet worked perfectly since I only want to check at startup if a device is attached.
- AbandonedCartHonored GuestSorry to dig this one back up, but I am trying to detect the Gear VR on-the-fly and have not had much luck.
I have an OVRCamera prefab disabled by default and an external script that checks for the device and enables it using Ovr.Hmd.Detect() > 0. I have tried both with the prefab enabled and disabled, and also with device.isPresent.
It appears to always return true for all checks if the prefab is enabled, and always return false when it's disabled. There is no actual hardware detection happening. Is it just mobile not having the detection or is there a new way to do this? - JasonHvrHonored GuestUnity now has a built-in way to detect this.
http://forum.unity3d.com/threads/simply ... st-2368233
Docs: http://docs.unity3d.com/ScriptReference ... esent.html
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 3 years ago
- 2 years agoAnonymous