Read controller data from outside VR Rig with action based input system

2.4k views Asked by At

I'm having trouble using the new action based input system in Unity OpenXR.

With the old (device based) input system it was possible to retrieve an input device object from outside the XR Rig using the InputDevices.GetDeviceAtXRNode(<node>) function.

For example: This is what I would do in the old system to retrieve position data of the right hand controller:

InputDevices.GetDeviceAtXRNode(XRNode.RightHand).TryGetFeatureValue(CommonUsages.devicePosition, out Vector3 position);
InputDevices.GetDeviceAtXRNode(XRNode.RightHand).TryGetFeatureValue(CommonUsages.deviceRotation, out Quaternion rotation);

Unfortunatly I can't find a way to do the same thing with the new action based input system. All the documentation that I could find on this topic refers to the old way of doing it. It appears that this method does not work anymore.

So, is there a way to retrieve an input device from outside the XR Rig using the new action based input system?

In case it helps: My Unity version is 2020.3.4f1 and I'm using the OpenXR plugin version 1.0.3.

Any help is greatly appreciated.

1

There are 1 answers

1
Spartacus On BEST ANSWER
ActionBasedController[] controllerArray = ActionBasedController.FindObjectsOfType<ActionBasedController>();
ActionBasedController controller = controllerArray[0];

By calling this method you get all ActionBasedControllers returned as an array. The controller can be identified by their name.

controller.name.Equals("Left Controller")

The trigger value can be read by following command:

//Position
controller.positionAction.action.ReadValue<float>();
//Trigger
controller.activateAction.action.ReadValue<float>();
//Grip
controller.selectAction.action.ReadValue<float>();