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.
Prerequisites
A data asset + registry (Quick Start). This path is for settings that drive live state; for plain persistence use the keyed store instead.
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.
Screenshot pending
Images/CrimsonSettings/howto-bind-delegates.png| 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) |
Verify
Dragging the slider calls your
OnSetValue immediately; reopening the screen shows the game's current value via OnGetValue.Unbound = internal storage
Leave a setting's delegates unbound and it stores its value internally (useful for a setting your game reads elsewhere). Tick Persist To Shared Store to also save that internal value across sessions.
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.