Course contentsShow
← Unity Game Development
Lesson 116 of 8282. Scripting and LifecycleFree lesson

Building a Rebindable Input Menu

Learners will develop a functional settings menu that allows players to remap their own control keys at runtime.

In this lesson, you will learn how to empower your players to customize their gameplay experience by remapping their own input keys at runtime.

The Core Concept

When we define InputAction assets, Unity stores them as pre-configured "bindings." To make these rebindable, we use the InputActionRebindingExtensions class. Instead of hard-coding a key like "Space" to "Jump," we create a UI button in your settings menu that enters a "listening state." When the player clicks this button, the system stops waiting for the original input and instead listens for the next key or button press the player makes. Once detected, the system saves that new key into the InputAction and updates the control scheme instantly.

Setting Up the Rebind

To initiate a rebind, you call the PerformInteractiveRebinding() method on your action. This method effectively "replaces" the default binding with whatever the user presses next. Here is a simplified way to trigger this from a UI button click:

public void StartRebinding(InputAction actionToRebind)
{
    // Disable the action so we can modify it
    actionToRebind.Disable();

    // Begin the rebinding process
    var rebindOperation = actionToRebind.PerformInteractiveRebinding()
        .WithControlsExcluding("<Mouse>/position") // Prevent accidental mouse movement
        .OnComplete(operation => 
        {
            // Clean up and re-enable the action
            actionToRebind.Enable();
            operation.Dispose();
        })
        .Start();
}

Why It Matters

By using this pattern, you move away from static, "developer-defined" controls toward a player-centric experience. Because the Input System Package handles the mapping in the background, you don’t have to manually write if statements checking for different keys. The system handles the "swapping" of the underlying binding, meaning your existing movement or combat scripts (which you already learned to write using InputAction callbacks) will continue to work perfectly without you needing to change a single line of your gameplay logic.

Key Takeaway: By using PerformInteractiveRebinding(), you can turn any UI interaction into a powerful customization tool that updates control mappings in real-time without rewriting your core game logic.