Skip to Content

Configs

This API is used to retrieve configurations from the Gamebeast platform.

For more information about Configurations, visit the Configurations Guide.

var gamebeastConfigs = GamebeastSdk.Configs;

Values are addressed by dot-path where the first segment is the configuration alias: "MyConfig.PlayerSpeed" reads the PlayerSpeed key of the MyConfig configuration. Paths can reach deeper ("MyConfig.UI.ButtonColor") and index arrays ("MyConfig.Levels.0"). A bare alias ("MyConfig") returns the whole configuration document.

Configurations are evaluated for the local user: if the user is enrolled in an active experiment, the values returned already include the assigned group’s changes.

Configurations load on demand. The first access through any of these methods fetches the configuration automatically. Declaring configurations in GamebeastSettings.Configurations additionally preloads them at startup and lets OnReady await them. Configurations are cached on-device, so values are available instantly on launch and offline.

Get<TValue>(configPath)

→ TValue

This method retrieves a configuration value from Gamebeast, converted to TValue. Returns default(TValue) when the path is missing or the configuration has not loaded yet. Prefer Observe when the value may still be loading.

configPath

string

The path of the configuration value to retrieve.

Usage

var playerSpeed = gamebeastConfigs.Get<float>("MyConfig.PlayerSpeed"); // Whole configuration document into a class public class MyConfigData { public float PlayerSpeed; } var myConfig = gamebeastConfigs.Get<MyConfigData>("MyConfig");

Get<TValue>(configPath, defaultValue)

→ TValue

This method retrieves a configuration value from Gamebeast, falling back to defaultValue when the path is missing or conversion fails.

configPath

string

The path of the configuration value to retrieve.

defaultValue

TValue

The value returned when the path is missing or conversion fails.

Usage

var playerSpeed = gamebeastConfigs.Get("MyConfig.PlayerSpeed", 16f);

TryGet<TValue>(configPath, out value)

→ bool

This method attempts to retrieve a configuration value from Gamebeast. Returns false when the path is missing or conversion fails.

configPath

string

The path of the configuration value to retrieve.

value

out TValue

The retrieved value when the method returns true.

Usage

if (gamebeastConfigs.TryGet<float>("MyConfig.PlayerSpeed", out var playerSpeed)) { // Value was available, do something. }

IsReady

→ bool

This property indicates whether all configurations declared in GamebeastSettings.Configurations have been loaded and are ready to be accessed.

Usage

if (gamebeastConfigs.IsReady) { // Configurations are ready to be accessed, do something. }

OnReady(callback)

→ IDisposable

This callback is triggered when the configurations declared in GamebeastSettings.Configurations are fully loaded and ready to be accessed. If the configurations are already loaded, the callback will be invoked immediately upon subscription.

callback

Action

The callback function to be invoked when configurations are ready.

Usage

gamebeastConfigs.OnReady(() => { // Configurations are ready to be accessed, do something. });

OnChanged(configPath, callback)

→ IDisposable

This callback is triggered whenever the value at a specific configuration path changes. It does not fire for the initial load; use Observe for that.

configPath

string

The path of the configuration value to listen for changes.

callback

Action

The callback function to be invoked when the value changes.

Usage

gamebeastConfigs.OnChanged("MyConfig.PlayerSpeed", () => { var newValue = gamebeastConfigs.Get<float>("MyConfig.PlayerSpeed"); Debug.Log($"Config 'MyConfig.PlayerSpeed' changed! New value: {newValue}"); });

Observe<TValue>(configPath, callback)

→ IDisposable

Similar to OnChanged, this callback fires with the current value as soon as it is available, and again with the new value each time it changes. This is the best fit for values that may still be loading.

configPath

string

The path of the configuration value to observe.

callback

Action<TValue>

The callback function to be invoked with the value when it is ready, or is changed.

Usage

gamebeastConfigs.Observe<float>("MyConfig.PlayerSpeed", playerSpeed => { Debug.Log($"Player speed is now {playerSpeed}"); });

RefreshAsync()

→ Task

This method forces a refresh of all known configurations now, in addition to the automatic background refresh.

Usage

await gamebeastConfigs.RefreshAsync();