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

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:

  • OpenVR wiki
  • List of ETrackedDeviceProperty values

Just stumbled upon this old question and I guess accepted answer was strictly correct when it was asked - there's a direct way to do it now, though: you can use GetTrackedDeviceClass.

It will return value of an enum ETrackedDeviceClass. Possible values are:

  • Invalid - if there's no tracked device under this index,
  • HMD - if the device is a headset,
  • Controller - if the device is, well, controller - this is one of your cases,
  • GenericTracker - this is another one of your cases
  • TrackingReference - for base stations, supporting cameras etc,
  • DisplayRedirect - by documentation - "Accessories that aren't necessarily tracked themselves, but may redirect video output from other tracked devices"
  • Max - this one is undocumented and I haven't stumbled upon it yet