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

Designing Chorded Input Action Systems

You will build a chorded input architecture that allows players to perform secondary actions by holding a modifier key alongside primary input buttons.

In this lesson, you will learn how to build a robust chorded input system that allows players to execute unique abilities by combining a "modifier" key with standard input buttons.

The Logic of Chording

A "chord" occurs when two inputs are pressed simultaneously, where one acts as a state modifier (like Shift or Ctrl) and the other as the action trigger. In the Enhanced Input system, we don't want to create hundreds of redundant actions. Instead, we want to treat the modifier as a state machine that redirects our standard input logic.

Implementing the State

The cleanest way to handle this is by maintaining a boolean flag in your Character class that tracks the state of your modifier key. You can bind the modifier key to a simple Started and Completed event to toggle this state:

void AMyCharacter::OnModifierPressed() { bIsModifierActive = true; }
void AMyCharacter::OnModifierReleased() { bIsModifierActive = false; }

Routing the Actions

When your primary action (e.g., Jump) is triggered, your input callback function should check the bIsModifierActive flag. By using a simple branch, you can branch the logic to perform a standard action or a "chorded" variant:

void AMyCharacter::HandleJumpAction(const FInputActionValue& Value)
{
    if (bIsModifierActive)
    {
        PerformSuperJump(); // The Chorded Action
    }
    else
    {
        PerformStandardJump(); // The Primary Action
    }
}

Why This Architecture?

By centralizing the logic inside your ACharacter class, you avoid polluting your Input Mapping Contexts with every possible combination of keys. This approach keeps your project scalable; if you want to add a third modifier (like Alt), you can simply convert the boolean into an Enum to manage complex input states cleanly. Always ensure your modifier key is bound in the same InputMappingContext as your primary actions to ensure the state remains synchronized during the frame.

Key Takeaway: Chorded input systems rely on state-tracking variables that act as logic gates, allowing you to repurpose standard button inputs for secondary abilities without duplicating input mapping complexity.