Flagsmith for Unity

Reading flags

Flags flags = flagsmith.Flags;

bool on      = flags.IsEnabled("new_shop");            // false when missing
float speed  = flags.GetValue("run_speed", 7f);        // 7 when missing, null or not a number
string label = flags.GetValue("cta_text", "Play");
Flag raw     = flags.Get("run_speed");                 // null when missing; raw.Value is the text value
FlagSource s = flags.Source;                           // Server, Cache or Defaults

GetValue<T> converts with the invariant culture, so "3.5" reads as 3.5 on a device set to a comma-decimal locale. For bool, it parses the value. Use IsEnabled for the flag's on/off state.

Binding fields with [FlagsmithValue]

[FlagsmithValue("run_speed")] float runSpeed = 7f;
[FlagsmithValue("lives")] public int Lives { get; private set; } = 3;
[FlagsmithValue("double_jump")] bool doubleJump;

void Awake() => flagsmith.Bind(this);

Reacting to changes

flagsmith.FlagsChanged += flags => ui.SetShopVisible(flags.IsEnabled("new_shop"));

FlagsChanged runs on the main thread after the first successful fetch and whenever a flag's state, value or variant changes. It does not run when a refresh returns the same flags.