I want to track the position of a (Vive) Tracker with the native Unity XR classes.
The InputTracking.GetLocalPosition method, doesn’t work in this case, because there can be multiple tracker: Unity - Scripting API: XR.InputTracking.GetLocalPosition
This method works, it returns a list of all states and there is also a entry for the “HardwareTracker” which gives the correct values for the connected Vive Tracker.
But my question is: Is there abetter way to handle this? Because I have to update the position every Update and it feels kinda weird to iterate the list every frame to get the “HardwareTracker” state from the updated list.
I tried to store the reference of the “HardwareTracker” state, but they are structs so it’s not possible.
The state also has some (hardware) id property but I couldn’t find any way to use this id to get the tracking information. The only methods I found are the two linked above.
I don’t want to use the SteamVR plugin, I know that it would be easier to handle tracker that way, I’m only asking about the native Unity XR.
I didn’t find a better solution, so I used the “dirty” method to get all nodes every update and iterate the returned list to update all “HardwareTracker”.
Im not sure if the newer Unity versions have new methods to handle this in a “cleaner” way, because I don’t work on the project anymore.
I think the “easiest” way to deal with the (Vive-)Tracker is to use the SteamVR plugin.
This would allow you to search devices by role, and then you can get the CommonUsages.DevicePosition and CommonUsages.DeviceRotation features every frame. It reduces the iteration of nodes, and let’s you cache and keep. Be sure to check InputDevice.isValid before using each frame in case it disconnects.
And in 2019.2 we will be adding InputDevices.OnDeviceConnected, and InputDevices.OnDeviceDisconnected APIs so you can listen for new devices instead of searching for new devices as well.
Looks good. I also like the new TryGetFeatureValue methods! I didn’t try them yet, but it looks like we can call these methods to get the controller inputs instead of setting up input mappings and string names. Also haptics, awesome
Im not sure if you are allowed to talk about this yet, but will these APIs also work for the Oculus Quest, which will be releases “soon”?
I can say that all XR devices that have native Unity support will work through these APIs, and we will be diligent in making sure the usages continue to make cross platform easier.
And yes, no more string mappings, no more remembering that the left trigger is 9, and the right is 10, and scripts can be dragged and dropped in without requiring project setting changes in order to access XR inputs.
I know this is a “old” thread, but I wanted to ask here instead of making a new one. Today is the official release of the Oculus Quest, I think all NDAs etc should be gone. So I wanted to ask which version of Unity I need for the Quest to use the above API. Does any of the current Unity versions have native support for the Quest?
Again sorry for posting to an old thread but right now the new input system package has its own version of TrackedPoseDriver. As opposed with the “legacy” TrackedPoseDriver in the XRInputs package, is it able to track several Vive trackers at once and is it possible to bind roles for e.g like waist, legs for full-body tracking?
// on start
var allDevices = new List<InputDevice>();
InputDevices.GetDevices(allDevices);
InputDevice tracker = allDevices.FirstOrDefault(d => d.role == InputDeviceRole.HardwareTracker);
// on update
tracker.TryGetFeatureValue(CommonUsages.devicePosition, out var pos);
tracker.TryGetFeatureValue(CommonUsages.deviceRotation, out var rot);
// NOTE!!! pos and rot are in world position so you have to translate it to floor
I have found information to connect the Vive trackers but they all use old SteamVR plugin. Is there an Unity XR or OpenVR solution yet? What are my options or is SteamVR plugin it?