In this lesson, you will learn how to use priority-based input overriding to ensure that localized gameplay actions—like opening a chest or using a terminal—successfully intercept inputs that would otherwise trigger global character movement.
The Problem of Input Conflict
When your player moves around the world, they usually rely on a "Default" InputMappingContext (IMC) that maps sticks and keys to locomotion. However, when the player interacts with a specific object, you often want to disable that movement while enabling interaction-specific controls (e.g., navigating a UI or operating a keypad). If both contexts are active, your character might keep walking while they are trying to dial a code.
Using Priority for Overrides
The Enhanced Input system allows you to add multiple InputMappingContexts to the EnhancedInputLocalPlayerSubsystem. Each context has a Priority value; a higher integer value ensures that context is processed before others. If a high-priority context consumes an input (like the "Interact" key), the lower-priority contexts are effectively overridden.
To manage this, we modify our subsystem behavior dynamically. When entering an interactive state, we push a "Locked" context with a higher priority:
// Add the Interaction Context with a priority of 1 (higher than default 0)
void AMyCharacter::EnterInteractionMode()
{
if (auto* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetController()->GetLocalPlayer()))
{
Subsystem->AddMappingContext(InteractionIMC, 1);
}
}
Ensuring Precedence
By assigning the InteractionIMC a priority of 1 and keeping the MovementIMC at 0, the system checks your interaction bindings first. If you want to stop movement entirely during this phase, you can either create an empty "Locked" context with high priority to "block" movement keys or simply remove the MovementIMC temporarily using RemoveMappingContext.
Using priority-based overrides keeps your input logic clean, avoiding messy boolean checks like bIsInteracting inside your Tick or character movement functions. It delegates the decision-making to the Input System itself.
Key Takeaway: By assigning higher integer priorities to specific interaction contexts, you force the input system to process local, context-sensitive actions before falling back to your global movement controls.