I can’t get ALL the InputControl from an InputAction, I either get the gamepad or the keyboard controls, but I can’t get both at the same time. How to get ALL the controls?
public static List<InputControl> GetControls(InputAction _action)
{
var result = new List<InputControl>();
var controls = _action.controls;
Debug.Log("_action.controls: " + _action.controls.Count);
// => is only gamepad or keyboard based on which device I used last. I want to get ALL the controls
foreach (var c in controls)
{
Debug.Log($"{c.name}");
result.Add(c);
}
return result;
}
When you’re using control schemes, the actions will be switched between schemes according to what the user currently uses and at any one time only have the devices and bound controls for the active control scheme.
Getting all controls in the system that could be bound to the action won’t work using InputAction.controls except if avoiding/circumventing the control scheme mechanism.
If you simply want to get an answer to “based on this action’s bindings, what controls on devices currently present could potentially be bound to the action”, one way to do it would be like so
var controls = default(InputControlList<InputControl>);
foreach (var binding in action.bindings)
InputSystem.FindControls(binding.effectivePath, ref controls);
(Note that InputControlList needs disposing to not leak memory)
What’s the problem you’re trying to solve?
1 Like
I wanted to pass an action and a control scheme to this method so that I can get all controls that fit a certain scheme.
public static List<InputControl> GetValidControls(InputAction _action, InputControlScheme _scheme)
{
var controls = default(InputControlList<InputControl>);
foreach (var binding in _action.bindings)
InputSystem.FindControls(binding.effectivePath, ref controls);
var result = new List<InputControl>();
foreach (var c in controls)
{
if (_scheme.SupportsDevice(c.device))
{
result.Add(c);
}
}
controls.Dispose();
return result;
}
With this information I will use it to show sprites based on what the action and input is.
The left side = the action’s name.
The right side = a Key enum or GamepadButton enum is fed to a method that finds a sprite of the button.

This is the code that finds the sprites based on the enums of the InputControl (Key, GamepadButton or mouse click). But I can’t find the GamepadButton or the mouse click yet.
public static string GetSpriteName(InputControl _inputControl)
{
var keyControl = Keyboard.current[_inputControl.displayName] as KeyControl;
if (keyControl != null)
{
var keyCode = keyControl.keyCode;
var spriteName = GetSpriteName(keyCode);
// Debug.Log("spriteName: " + spriteName);
return spriteName;
}
var buttonControl = Gamepad.current[_inputControl.displayName] as ButtonControl;
if (buttonControl != null)
{
// TODO: find out what GamepadButton this control requires.
// var spriteName = GetSpriteName(/*GamepadButton*/);
}
var isMouse = _inputControl.device == Mouse.current;
if (isMouse)
{
// TODO: find out what mouse click this control requires
// var spriteName = GetSpriteName(/*int*/);
}
return string.Empty;
}