0

I have a Unity game that runs on both Android Cardboard and Oculus Go. I'm trying to determine whether the Go's controller is connected.

I imported the Oculus integration package from the Unity asset store (though I'm not sure it's actually required... I've gotten the impression that Oculus support has been built into Unity since at least 2018.3, if not 2018.2 or earlier). I also deleted Cardboard and added Oculus as Virtual Reality SDKs in Player settings.

The following code executes in the Start() method that initializes most of my game:

void Start() {
    // ...
    if (OVRInput.IsControllerConnected(OVRInput.Controller.RTrackedRemote)) {
        // do something visible
    }
    // ...
}

The problem is, OVRInput.IsControllerConnected(...) always returns false, and the code inside the block never executes.

Other things I've tried:

  • Moved the call to OVRInput.IsControllerConnected() from Start() to Update(), just in case it's an initialization-time issue. No success. Same result.

  • Instead of using OVRInput.Controller.RTrackedRemote as the argument, I tried the other objects... LTrackedRemote, Active, All, Gamepad, LTouch, RTouch, Remote, Touch, Touchpad, and None. All of them except '.None' returned false. '.None' returned true.

  • I set a breakpoint on the line calling OVRInput.IsControllerConnected() (after moving it to Update()), then called OVRInput.GetConnectedControllers() in VS2017's immediate window... it returned "None". Ditto for OVRInput.GetActiveController().

The game itself began as Android Cardboard. So far, the only major changes I've made to it are:

  • Importing the Oculus support library from Unity's Asset store.

  • In Player -> XR Settings, I deleted "Cardboard" and added "Oculus" as a VR SDK

  • In Build Settings, I changed the build method from 'Gradle' to 'Internal' (Gradle builds failed... I've seen posts from summer 2018 saying it's a Unity bug, but I'm not sure whether that's still current info... regardless, changing from Gradle to Internal made THAT error go away).

Most notably, I have NOT added any Oculus-specific prefabs, or changed/removed any of the GoogleVR-specific prefabs.

Bitbang3r
  • 6,826
  • 5
  • 27
  • 40

1 Answers1

1

I know you tried moving IsControllerConnected to Update but did you try GetConnectedControllers in Update after a second? That's what did the trick for me. So in Update():

        // initialize hand once after one second of start
        if(!handInitialised){
                initialWait += Time.deltaTime;
                if(initialWait > 1f){
                    OVRInput.Controller c = OVRInput.GetConnectedControllers();
                    if(c == OVRInput.Controller.LTrackedRemote || c == OVRInput.Controller.LTouch){
                        //
                    }
                    //
                    handInitialised = true;                
                }
        }