Interactive rebinding
Note
To download a sample project which demonstrates how to set up a rebinding user interface with Input System APIs, open the Package Manager, select the Input System Package, and choose the sample project "Rebinding UI" to download.
Runtime rebinding allows users of your application to set their own bindings.
To allow users to choose their own bindings interactively, use the InputActionRebindingExtensions.RebindingOperation class. Call the PerformInteractiveRebinding() method on an Action to create a rebinding operation. This operation waits for the Input System to register any input from any Device which matches the Action's expected Control type, then uses InputBinding.overridePath to assign the Control path for that Control to the Action's bindings. If the user actuates multiple Controls, the rebinding operation chooses the Control with the highest magnitude.
Important
You must dispose of InputActionRebindingExtensions.RebindingOperation instances with Dispose(), so that they don't leak memory on the unmanaged memory heap.
void RemapButtonClicked(InputAction actionToRebind)
{
var rebindOperation = actionToRebind
.PerformInteractiveRebinding().Start();
}
The InputActionRebindingExtensions.RebindingOperation API is highly configurable to match your needs. For example, you can:
Choose expected Control types (
WithExpectedControlType()).Exclude certain Controls (
WithControlsExcluding()).Set a Control to cancel the operation (
WithCancelingThrough()).Choose which bindings to apply the operation on if the Action has multiple bindings (
WithTargetBinding(),WithBindingGroup(),WithBindingMask()).
Refer to the scripting API reference for InputActionRebindingExtensions.RebindingOperation for a full overview.
Note that PerformInteractiveRebinding() automatically applies a set of default configurations based on the given action and targeted binding.