How to determine whether a SteamVR_TrackedObject is a Vive Controller or a Vive Tracker

Liam Ferris picture Liam Ferris · Apr 3, 2017 · Viewed 8.8k times · Source

What is the best way to determine whether a SteamVR_TrackedObject is a Vive Controller and a Vive Tracker?


When 0 Controllers and 1 Tacker is paired:

The Tracker is taken as Controller (right) of the CameraRig.

When 1 Controller and 1 Tacker is paired:

The Tracker is set to Device 2.

When 2 Controllers and 1 Tacker is paired:

Creating a third SteamVR_TrackedObject and placing it in the CameraRig's objects array. Also when a controller looses tracking so does the tracker.


In each scenario the Tracker ends up being a different SteamVR_TrackedObject.index. What is the best way to check if a SteamVR_TrackedObject is a Tracker, or to find which index the Tracker is?

Answer

Liam Ferris picture Liam Ferris · Apr 3, 2017

The only method of checking a SteamVR_TrackedObject that I have found yet is to check the ETrackedDevicePoperty.Prop_RenderModelName_String:

uint index = 0;
var error = ETrackedPropertyError.TrackedProp_Success;
for (uint i = 0; i < 16; i++)
{
    var result = new System.Text.StringBuilder((int)64);
    OpenVR.System.GetStringTrackedDeviceProperty(i, ETrackedDeviceProperty.Prop_RenderModelName_String, result, 64, ref error);
    if (result.ToString().Contains("tracker"))
    {
        index = i;
        break;
    }
}

Then you can set SteamVR_TrackedObject.index to index:

GetComponent<SteamVR_TrackedObject>().index = (SteamVR_TrackedObject.EIndex)index;

Finding any documentation on this has been pretty difficult so far but here's some sources: