Fetch XR handed-ness from an InputAction?

I’m hoping to create two generic action maps - each that uses values such as:

XR Controller/PrimaryButton
XR Controller/SecondaryButton

And then filter those input actions myself to “left hand” and “right hand” so the player can easily swap their left/right action maps.

I’m already using a monobehaviour and listening for the mapped events, but I see no way to filter or test if something is a left hand, other than something dumb like name.Contains("Left") which is pretty shaky.

Is there some sort of left/right node buried in there that I can pull out?

Right now the only solution I can see is to make duplicate action maps -

XR Controller (Left) / PrimaryButton
and
XR Controller (Right) / PrimaryButton

and manually swap between them with my own logic. This works okay, but any time I update the input controls I have to duplicate changes in multiple places to pull this off. Which is dangerous and frustrating!

void OnMyAction(InputAction.CallbackContext context)
{
    var device = context.control.device;
    if (device.usages.Contains(CommonUsages.LeftHand))
        Debug.Log("Action triggered from left hand");
    else if (device.usages.Contains(CommonUsages.RightHand))
        Debug.Log("Action triggered from right hand");
    else
        Debug.Log("Action triggered with... no hands...");
}
1 Like

That worked great, thanks!

I sure wish CommonUsages had an enum I could use to make a dropdown selector or something, but I can work with this. :slight_smile:

While not exactly the same thing, it is possible to get “common usages” for a layout which could be used for populating a dropdown.

// Get common ussags for "XRController" layout.
var usages = InputSystem.LoadLayout("XRController").commonUsages;