Disambiguation for using multiple of the same controller for one player-

Recommend checking out the “Custom Device Usages” sample (can be installed from the input system package page in the Package Manager window).

The comments in the sample C# code hopefully make it relatively straightforward to follow.

Gist:

  • Any device can be “tagged” with arbitrary “usages” (just strings).
  • These can be bound to from actions using paths such as "<Gamepad>{Left}/buttonSouth" (drop binding path into text mode with little “T” icon).
  • For the control picker dropdown to be aware of them and present them as options in the UI, they need to be advertised as “common usages” for a specific layout. See the sample code.
  • To associate usages with a device, call SetDeviceUsage or AddDeviceUsage.
// Create two input actions where the "LeftHand" joystick
// controls planar movement and the "RightHand" joystick
// controls mouse look.
var move = new InputAction(binding: "<Joystick>{LeftHand}/stick");
var look = new InputAction(binding: "<Joystick>{RightHand}/stick");

// Make joystick #0 "LeftHand" and joystick #1 "RightHand".
InputSystem.AddDeviceUsage(Joystick.all[0], CommonUsages.LeftHand);
InputSystem.AddDeviceUsage(Joystick.all[1], CommonUsages.RightHand);

// Can be changed at any time. Say you want to later swap hands.
InputSystem.RemoveDeviceUsage(Joystick.all[0], CommonUsages.LeftHand);
InputSystem.RemoveDeviceUsage(Joystick.all[1], CommonUsages.RightHand);
InputSystem.AddDeviceUsage(Joystick.all[0], CommonUsages.RightHand);
InputSystem.AddDeviceUsage(Joystick.all[1], CommonUsages.LeftHand);

// Or if you just want to replace usages on the device wholesale.
InputSystem.SetDeviceUsage(Joystick.all[0], CommonUsages.LeftHand);
InputSystem.SetDeivceUsage(Joystick.all[1], CommonUsages.RightHand);

////EDIT: One idea that’s been floating around in my head is to make it possible to set these usage tags on the devices you add as requirements in control schemes. So you could, say, add a control scheme “TwoJoysticks” and add two joysticks and in the control scheme properties, tag one as “LeftHand” and the other as “RightHand” and then the control picker would be aware of this without having to do the “commonUsages” dance.

1 Like