How to know when a SteamVR controller or a VIVE tracker gets connected in Unity

For my PhD thesis I need to know in SteamVR when a device gets connected if its a generic tracker or if it’s a typical SteamVR controller. After searching for a while I found this solution here¬†that works but relies on comparing the render model of the device to a string. I wasn’t satisfied with this solution.

After digging a while inside the SteamVR scripts I found out that there is an event that you can subscribe to and lets you know if a device gets connected or disconnected and by doing a reverse check up on the Tracked device class with the index you can know if its a SteamVR Controller or a VIVE tracker.

This code snippet prints when a controller or a generic tracker gets connected.

Its a pretty handy script if you want to know if a controller or a tracker got connected!, hope this helps you out :).

3 Responses to “How to know when a SteamVR controller or a VIVE tracker gets connected in Unity”

  1. Duane says:

    Thanks for this, the recent SteamVR update broke our system as well, where we have multiple trackers, some flashed with controller JSONS, others as generic trackers.

    I will fall back on the string comparison for now, as dodgy as that is.

  2. Juan Sebastian says:

    Hey Michael,

    Indeed, you are right, this method doesnt work anymore reliably since Steam was updated. I’m still trying to see how to know reliably if a tracker or a controller is connected.

  3. Michael Burton says:

    At least for me, at the moment, this is unreliable. There are cases where this will identify trackers as controllers. This seems to occur when you are running with less than 2 controllers. Seems that it used to work even for that case, but something changed, and currently, I need to use the less pretty string compare. With things changing (SteamVR updates, and such), your circumstance may vary, but thought I’d mention, in case anyone else runs into the same issue.