Skip to Content
Unity SDKOverview

Unity SDK

Use this section to review required setup functions and examples for the Unity SDK.

Refer to the Installation section for installation information.

Calling into Gamebeast from Unity

gamebeast_setup.cs
using UnityEngine; using Gamebeast; public class GamebeastStarter : MonoBehaviour { void Start() { GamebeastSdk.Setup("abcd-efgh-1234-5678"); } }

The SDK can also initialize itself automatically from a settings asset, with no setup code required. See Automatic Initialization below.

SDK Methods

Setup(apiKey)

→ void

This function must be called once to initialize the Gamebeast SDK. Attempting to call any other SDK method before calling Setup will result in an error.

apiKey

string

The API key for the SDK.

Usage

GamebeastSdk.Setup("abcd-efgh-1234-5678");

Setup(settings)

→ void

Initializes the Gamebeast SDK with a full settings object for additional configuration.

settings

GamebeastSettings

The settings object for the SDK.

Types

public sealed class GamebeastSettings { // Your Gamebeast project API key. Required. public string ApiKey; // Optional distinct id for the local player. When omitted, the SDK generates an // anonymous id on first launch and persists it on the device, so the same user // is reported across sessions. public string DistinctId; // Which Gamebeast environment to target. Auto resolves to Development in the // Unity Editor and Production in builds. public GamebeastEnvironment Environment = GamebeastEnvironment.Auto; // Optional: target a custom environment by its alias, as configured in the // Gamebeast dashboard (e.g. "staging"). Takes precedence over Environment when set. public string CustomEnvironment; // Optional: configurations to preload at startup, by alias. Preloaded // configurations are fetched immediately and gate Configs.IsReady/OnReady. public string[] Configurations; // Optional custom properties describing the local user, sent as targeting // context with every configuration evaluation. public Dictionary<string, object> UserProperties; // How often (seconds) the SDK re-checks the backend for configuration changes. // Set to 0 to disable background refresh. public float ConfigRefreshIntervalSeconds = 60f; // Rotate the session id when the app has been backgrounded for at least this // many seconds. Set to 0 to keep one session per app run. public float SessionTimeoutSeconds = 1800f; // Enables verbose SDK logging in the console. public bool DebugLogging = false; // Override the Gamebeast API base URL. Leave as-is for production use. public string ApiUrl = "https://api.gamebeast.gg"; }

Usage

GamebeastSdk.Setup(new GamebeastSettings { ApiKey = "abcd-efgh-1234-5678", DistinctId = "player-123", Configurations = new[] { "MyConfig" }, });

Identify(distinctId)

→ void

Switches the local user’s distinct id, for example after a login. Configurations are re-evaluated for the new user right away, and experiment assignments update with them. Markers recorded before the switch keep the id they were recorded under.

The id is not persisted. Call Identify again on the next launch once your login state has restored, or pass it in GamebeastSettings.DistinctId.

distinctId

string

The distinct id for the local user.

Usage

GamebeastSdk.Identify("player-123");

ResetIdentity()

→ void

Reverts to the device’s persisted anonymous distinct id, for example after a logout.

Usage

GamebeastSdk.ResetIdentity();

Shutdown()

→ void

Flushes pending data and tears the SDK down. Setup may be called again afterwards.

Usage

GamebeastSdk.Shutdown();

GetService<TService>()

→ TService

This method will attempt to fetch a service from the Gamebeast SDK by its public interface. All available services can be found documented here.

Usage

var markersService = GamebeastSdk.GetService<IMarkersService>();

SDK Properties

DistinctId

→ string

The effective distinct id for this session: the id supplied in settings or via Identify, or the anonymous id generated and persisted by the SDK. Null before Setup.

IsInitialized

→ bool

True once Setup has completed.

Automatic Initialization

Instead of calling Setup from a script, you can let the SDK initialize itself at startup:

  1. Create a settings asset via “Assets > Create > Gamebeast > Settings”.
  2. Fill in your API key in the inspector.
  3. Place the asset at Resources/GamebeastSettings in your project.

Calling Setup manually still works and takes precedence. Code-only options such as DistinctId and UserProperties are not available on the asset; use a manual Setup or Identify for those.

Accessing Services

After initializing the SDK, you can access various services provided by the Gamebeast SDK. Each service is accessible via a static property on the GamebeastSdk class.

Example: Accessing the Markers Service

var markersService = GamebeastSdk.Markers; markersService.SendMarker("example_marker", new { value = 42 });