- Home /
Unable to track multiple Input Devices with generic XR.InputDevices!!
Have spent over a day on this problem now, but no luck!
Objective: Be able to track multiple vive tracker and hand controller using XR.InputDeviceRole.
Approach: 1. At the start of the scene get the list of all input devices available. [Works] 2. In the update method "TryGetFeatureValue" for position, rotation and button inputs depending upon the Device role type. [Works]
Problem: As soon as I increase another object with either same or different device type (HardwareTracker & RightController), it fails to get the tracked values!
I have attached snippets of code here for reference. Would appreciate any help.
Thanks.
PS: All devices are properly tracked outside of Unity and can be seen in the default VR visualizer properly tracked. Also I do get values for all devices in first few frames (2/3) but it stops again and tracked device becomes invalid (in Unity).
static List<InputDevice> devices = new List<InputDevice>();
[SerializeField]
InputDeviceRole role;
public int ind = 0;
// Update is called once per frame
void Update()
{
InputDevices.GetDevicesWithRole(role, devices);
Debug.Log(devices.Count);
if (devices.Count > 0)
{
InputDevice device = devices[ind];
Vector3 position;
if (device.TryGetFeatureValue(CommonUsages.devicePosition, out position))
this.transform.position = position;
Quaternion rotation;
if (device.TryGetFeatureValue(CommonUsages.deviceRotation, out rotation))
this.transform.rotation = rotation;
}
}