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 pendingImages/CrimsonSettings/howto-bind-delegates.png
Registry -> K2_BindSetting (Setting, DevName) -> Switch on DevName -> 'MasterVolume': Cast to UCrimsonSettingValueScalar_BP -> bind OnGetValue = GetMasterVolume, OnSetValue = SetMasterVolume.
Value classDelegatePurpose
UCrimsonSettingValueScalar_BPOnGetValueRead the current value from game (returns double)
OnSetValueWrite the new value (double + ECrimsonSettingChangeReason)
OnGetFormattedTextOptional - custom display text
UCrimsonSettingValueDiscrete_BPOnGetOptionsReturn the option list (falls back to BPOptions)
OnGetIndexRead the current selection index
OnSetIndexWrite 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.