How-To: Bind a Setting to Game Code
Goal: make a setting read from and write to a live game value (a volume, a quality preset, a subsystem property) the instant it changes - using the K2_BindSetting delegates.
1. Handle K2_BindSetting
Populate From Data Asset fires K2_BindSetting once per created setting. Switch on DevName, cast to the value class, and bind its get/set delegates to your game functions.
In the registry Blueprint, use My Blueprint -> Functions -> Override and pick K2_BindSetting. Chain: K2_BindSetting -> Switch on Name (Selection = the event's Dev Name pin; add one output pin per setting you bind) -> Cast To CrimsonSettingValueScalar_BP (Object = the event's Setting pin).
From the cast result, drag off and use Bind Event to On Get Value and Bind Event to On Set Value, connecting each red delegate pin to a Custom Event - the first returns your game's current value, the second writes the new one. A discrete setting is the same shape against Cast To CrimsonSettingValueDiscrete_BP with Bind Event to On Get Index / On Set Index.
| Value class | Delegate | Purpose |
|---|---|---|
UCrimsonSettingValueScalar_BP | OnGetValue | Read the current value from game (returns double) |
OnSetValue | Write the new value (double + ECrimsonSettingChangeReason) | |
OnGetFormattedText | Optional - custom display text | |
UCrimsonSettingValueDiscrete_BP | OnGetOptions | Return the option list (falls back to BPOptions) |
OnGetIndex | Read the current selection index | |
OnSetIndex | Write the new index (int32 + reason) |
OnSetValue immediately; reopening the screen shows the game's current value via OnGetValue.See also
- How-To: Persist Settings with Zero Glue - when you only need the value saved, not a live callback.
- Concept: Value Types & Data Sources - delegates vs. C++ data sources vs. the keyed store.