Apply binding overrides in code
Change a binding's path, processors, or interactions at runtime without changing the binding itself, for example, to let users rebind their controls.
The examples on this page use the following variable:
playerInput: aPlayerInputcomponent.
Override a binding
To override the path of an action's binding, call ApplyBindingOverride:
// Rebind the "fire" action to the left trigger on the gamepad.
playerInput.actions["fire"].ApplyBindingOverride("<Gamepad>/leftTrigger");
In most cases, find the specific binding first, for example, with GetBindingIndexForControl, and then apply the override to that binding:
// Find the binding of the "Jump" action for the space key.
var jumpAction = playerInput.actions["Jump"];
var bindingIndex = jumpAction.GetBindingIndexForControl(Keyboard.current.spaceKey);
// Change it to the Enter key.
jumpAction.ApplyBindingOverride(bindingIndex, "<Keyboard>/enter");
The binding now uses the override instead of its own path. The binding itself doesn't change.
Note
The Input System doesn't save override properties with the actions, for example, when you call InputActionAsset.ToJson. To save and load user rebinds, refer to Save and load rebinds.
Override processors and interactions
To override a binding's processors or interactions, pass an InputBinding to ApplyBindingOverride. The Input System copies overridePath, overrideProcessors, and overrideInteractions from it, and replaces all three overrides on the binding. To keep the overrides you don't want to change, start from a copy of the binding:
// Find the binding of the "Jump" action for the space key.
var jumpAction = playerInput.actions["Jump"];
var bindingIndex = jumpAction.GetBindingIndexForControl(Keyboard.current.spaceKey);
// Copy the binding, including its current overrides, and change only the interactions.
var binding = jumpAction.bindings[bindingIndex];
binding.overrideInteractions = "hold(duration=0.5)";
jumpAction.ApplyBindingOverride(bindingIndex, binding);
Overridable binding properties
When you set an override property, it takes effect instead of the original property. All override properties are strings. The following properties of InputBinding have an override variant.
| Property | Override | Description | Example |
|---|---|---|---|
path |
overridePath |
Replaces the control path that determines which controls the binding uses. If you set overridePath to an empty string, the Input System disables the binding. |
"<Gamepad>/leftStick" |
processors |
overrideProcessors |
Replaces the processors on the binding. | "invert,normalize(min=0,max=10)" |
interactions |
overrideInteractions |
Replaces the interactions on the binding. | "tap(duration=0.5)" |