In this lesson, you will learn how to refine your player interactions by applying specific Input Triggers to your Enhanced Input Actions, allowing you to differentiate between a quick tap, a long hold, or a complex chorded button press.
The Role of Input Triggers
While Input Actions define what an input does (like "Jump" or "Interact"), Input Triggers define the behavioral requirement that must be met before that action fires. By adding triggers to your UInputMappingContext, you move away from simple boolean checks and toward sophisticated interaction patterns.
Configuring Common Patterns
You configure these triggers inside your Input Mapping Context (IMC) asset. Each action within the IMC can have one or more triggers added to its list. Here is how the most common patterns function:
- Pressed: The default behavior; fires immediately when the key goes down.
- Released: Fires only when the button is let go.
- Hold: Requires the player to press and maintain the input for a set duration (e.g.,
Hold Threshold). This is perfect for "Charge Up" mechanics or opening doors that require a physical delay. - Tap: Only fires if the player releases the button before the hold threshold expires. This is ideal for distinguishing between a quick light attack and a heavy charged strike.
- Chorded Action: Requires a primary button to be held while another is pressed (e.g.,
Ctrl + S). This effectively acts as a modifier for your existing actions.
Implementation Example
When you bind these in your Character Blueprint, the trigger logic handles the state transition automatically. If you set an action to use a "Hold" trigger, your C++ BindAction logic will only execute its callback once the hold duration is satisfied:
// In your SetupPlayerInputComponent
EnhancedInputComponent->BindAction(MyHoldAction, ETriggerEvent::Completed, this, &ACharacter::OnLongHoldComplete);
By layering these triggers, you avoid writing complex "timer-based" logic in your character class. The engine manages the state machine for you, ensuring the event only fires when the specific interaction pattern is validated.
Key Takeaway: Input Triggers act as a logic filter that dictates exactly which user interaction pattern (tap, hold, or chord) must be met before an action binding is triggered.