How-To: Let Players Rebind Chords
Goal: let each player set their own modifier on an action from a settings screen, persisted across sessions, with conflict detection and a display glyph.
Add Mapping Context With Chord Triggers.1. Mark the action rebindable
On the UInputAction, set Player Mappable Key Settings -> Class to CrimsonPlayerMappableKeySettings and give it a Name. That Name is the key per-player chord overrides are stored under.
Add Mapping Context With Chord Triggers injects a UInputTriggerCrimsonDynamicChord (with an empty DefaultChord, i.e. overrides-only) onto any mapping whose action uses UCrimsonPlayerMappableKeySettings and does not already have one. To also give it a designer default, add the trigger yourself and set both MappingName and DefaultChord.2. Read and write overrides
Get the UCrimsonInputUserSettings (see How-To: Get the Building Blocks step 3). Write with SetChordRequirement; read the effective value (override, else the inline default) with GetChordRequirementWithDefaults.
3. Validate before committing
Before writing a chord, call FindChordConflict (BlueprintPure) so two actions cannot end up on the same key with the same chord. It returns the first conflicting mapping + slot.
FName ConflictMapping; EPlayerMappableKeySlot ConflictSlot;if (UserSettings->FindChordConflict(Subsystem, TEXT("Ability1"),EPlayerMappableKeySlot::First, NewChord, ConflictMapping, ConflictSlot)){ShowConflictWarning(ConflictMapping, ConflictSlot);return; // do not commit}UserSettings->SetChordRequirement(TEXT("Ability1"), EPlayerMappableKeySlot::First, NewChord);
ClearChordRequirement removes one override; ClearAllChordRequirements resets them all; HasChordRequirement (BlueprintPure) tests for one.
4. Show the chord glyph
GetChordDisplayTextForAction (BlueprintPure) collapses the whole lookup - active profile -> bound key -> user override (or default) -> formatted text - into one call. Use it for key hints and action bars.
ChordMappings is SaveGame).See also
- How-To: Get the Building Blocks - getting the user settings (and the two Project Settings toggles).
- How-To: Add Modifier-Key Chords - the inline, non-rebindable path.
- Concept: The Chord System - how overrides win over defaults and how injection works.