Read Controller Data from Outside Vr Rig with Action Based Input System

Read Controller Data from Outside Vr Rig with Action Based Input System

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 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>();
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.