Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Setting a vive tracker to "Disable" role. Bindings are ignored?

Discussion in 'AR/VR (XR) Discussion' started by Airmouse, Mar 31, 2019.

  1. Airmouse

    Airmouse

    Joined:
    Jan 12, 2019
    Posts:
    107
    I am using SteamVR 2.0 and the bindings system.

    I am trying to set simple bindings for trackers so I may access pogo pin states in game.

    Currently I have set all of my trackers to role: "Disabled" and created bindings for: application_generated_unity_mygame_binding_vive_tracker.json.

    But in Unity I am unable to see any actions values from the trackers and they never change.

    If I set the trackers to role: "camera", "chest" or other similar then I can only have option to change the "Power" button action. so pogo pins are missing.

    Why did they make it impossible to use trackers?

    How do I get around this limitation

    [UPDATE]
    Strange stuff here,
    If I change a tracker to role: "camera" then immediately change it back to "disable" I see it remains as "/user/camera -vive_tracker" in the debugger.

    During this time all of my bindings work! But only for that one tracker :(
    I am guessing that SteamVR is bugged out, somehow this one tracker is not a disable/camera mix???

    But worse yet, it's a total hack, and I would never ask my customers do this.

    Why does this just seem so broken? Was it intentional?o_O
     
    Last edited: Mar 31, 2019
  2. StayTalm_Unity

    StayTalm_Unity

    Unity Technologies

    Joined:
    May 3, 2017
    Posts:
    182
    Try setting them to be handed. I don't use SteamVR 2.0, but when implementing the trackers through OpenVR internally, we found we would only get data from the pins when the tracker was being treated like a controller and set to be handed.
     
  3. Airmouse

    Airmouse

    Joined:
    Jan 12, 2019
    Posts:
    107
    Thank you for your advice. though I have tried handed, which kind of worked, but then I ran up against the issue of handType uniqueness.

    I add a hand.cs script to each tracker (dynamically), which requires me to set it's handType. But if two trackers share the same handType then it is impossible to read the IO from a specific tracker (I think).

    The only way I was able to make two trackers work independently was to create redundant bindings for 'camera' and 'keyboard' roles, then in Unity using OpenVR I check the device type via `ETrackedDeviceProperty.Prop_ControllerType_String` property to see if it is reporting as a 'vive_tracker_camera' or 'vive_tracker_keyboard'. This allows me to set the handType within a switch statement for all trackers when I dynamically adding the hand.cs script.

    Code (csharp):
    1. [Header ("VIVE TRACKERS")]
    2. public Transform[] viveTrackers;
    3. public LayerMask trackersHoverMasks; //layers that this tracker can hover onver
    4.  
    5. public void SetupTrackers() {
    6.     foreach (Transform viveTracker in viveTrackers) {
    7.         SteamVR_TrackedObject device = viveTracker.GetComponent<SteamVR_TrackedObject> ();
    8.  
    9.         var deviceType = GetDeviceType (device);
    10.  
    11.         if (!deviceType.ToLower().Contains ("tracker") || device.index == null || !device.isValid) {
    12.             continue;
    13.         }
    14.  
    15.         var trackerPrefab = Instantiate<GameObject> (TrackerLinkerPrefab, viveTracker);
    16.  
    17.         switch (deviceType) {
    18.         case "vive_tracker_camera":
    19.             AddHandTypedTracker(trackerPrefab, SteamVR_Input_Sources.Camera);
    20.             break;
    21.         case "vive_tracker_keyboard":
    22.             AddHandTypedTracker(trackerPrefab, SteamVR_Input_Sources.Keyboard);
    23.             break;        
    24.         case "vive_tracker":
    25.             if (trackerPrefab.GetComponent<Hand> ()) {//maybe it changed during gameplay?
    26.                 Destroy (trackerPrefab.GetComponent<Hand> ());//destroy the hand
    27.             }
    28.             break;        
    29.         }
    30.  
    31.     }
    32. }
    33.  
    34. string GetDeviceType (SteamVR_TrackedObject device) {
    35.  
    36.     var error = ETrackedPropertyError.TrackedProp_Success;
    37.     var result = new System.Text.StringBuilder((int)64);
    38.  
    39.     var capacity = OpenVR.System.GetStringTrackedDeviceProperty((uint)device.index, ETrackedDeviceProperty.Prop_ControllerType_String, null, 0, ref error);
    40.     if (capacity > 1)
    41.     {
    42.         result = new System.Text.StringBuilder((int)capacity);
    43.         OpenVR.System.GetStringTrackedDeviceProperty((uint)device.index, ETrackedDeviceProperty.Prop_ControllerType_String, result, capacity, ref error);
    44.     }
    45.  
    46.     return result.ToString ();
    47. }
    48.  
    49. void AddHandTypedTracker(GameObject trackerSphere, SteamVR_Input_Sources trackerType) {
    50.     var hand = trackerSphere.AddComponent<Hand> ();
    51.     hand.hoverLayerMask = trackersHoverMasks;
    52.     hand.hoverSphereRadius = 0.17f;
    53.     hand.useFingerJointHover = false;
    54.  
    55.     hand.handType = trackerType; //now set the handType for this tracker
    56. }
    It seems wasteful though to have to create the exact same bindings for all the roles: keyboard, camera, shoulders, waist, feet, so on.. just so Unity/SteamVR may access tracker's actions individually.

    Then again, maybe I'm just using it incorrectly..

    I wish SteamVR would make mo
     
    Last edited: Apr 1, 2019