Course contentsShow
← Unreal Engine Game Development
Lesson 243 of 8804. Advanced Input and PhysicsFree lesson

Developing Accessible Input Rebinding Interfaces

You will build a dynamic input rebinding system that allows players to customize their control schemes while maintaining complex modifier logic.

In this lesson, you will learn how to build a user-facing interface that allows players to remap their UInputAction keys dynamically while preserving complex input modifier logic.

The Logic of Remapping

When you allow players to remap keys, you aren't just changing a single button; you are modifying the UInputMappingContext. The Enhanced Input system handles this by allowing us to iterate through the mappings within a context and update the Key property associated with a specific action.

To create an accessible UI, you should treat the "Remapping" process as a two-step state machine:

  1. The Request: The player clicks a button in your UI, triggering a state where the system listens for the next physical input.
  2. The Assignment: The system captures the key and injects it back into the UEnhancedInputLocalPlayerSubsystem.

Practical Implementation

To update a mapping, you first need to locate the existing mapping within your UInputMappingContext. You cannot simply overwrite the data; you must remove the old mapping and add a new one with the updated key.

// Logic to update a mapping at runtime
void UMyInputSettings::RemapKey(UInputMappingContext* InputContext, UInputAction* Action, FKey NewKey)
{
    // 1. Remove the existing mapping for this action
    for (FEnhancedActionKeyMapping& Mapping : InputContext->GetMappings())
    {
        if (Mapping.Action == Action)
        {
            InputContext->UnmapAction(Action);
            
            // 2. Add the new mapping while preserving modifiers
            FEnhancedActionKeyMapping NewMapping = Mapping;
            NewMapping.Key = NewKey;
            InputContext->MapKey(Action, NewKey);
            break;
        }
    }
}

Preserving Complexity

The beauty of this approach is that FEnhancedActionKeyMapping objects contain the Modifiers array and Triggers array. By copying the existing mapping structure (NewMapping = Mapping) before applying the NewKey, you ensure that all complex logic—like "Dead Zones" for sticks or "Chorded" inputs—is automatically carried over to the new key binding.

Always provide visual feedback during the "listening" phase so the player knows the game is waiting for their input, preventing accidental overwrites.

Key Takeaway: To implement dynamic rebinding, update the UInputMappingContext by replacing specific FEnhancedActionKeyMapping entries, ensuring you preserve the original modifiers and triggers to maintain your input system's underlying complexity.