Flagsmith for Unity

Flagsmith for Unity

Flagsmith for Unity connects Unity games to Flagsmith, the open-source feature flag service. A game reads its tuning, switches and experiment variants from Flagsmith at runtime, so you can change them without a new build. It works with Flagsmith Cloud and self-hosted Flagsmith, and everything runs on Unity's main thread, so WebGL builds work too.

Flag Runner changing live while flags are edited in self-hosted Flagsmith

The sample game, Flag Runner, while server/demo.py edits its flags. Nothing is rebuilt or restarted.

Install

Unity 6 (6000.0) or newer. In Window > Package Manager > + > Install package from git URL, paste:

https://github.com/Harindulk/flagsmith-unity.git?path=/com.flagsmith.unity

Or add it to Packages/manifest.json:

"com.flagsmith.unity": "https://github.com/Harindulk/flagsmith-unity.git?path=/com.flagsmith.unity"

Add #v0.1.0 to the end of the URL to stay on a fixed release. Releases are listed on the releases page.

Unity also installs com.unity.nuget.newtonsoft-json, which the package depends on.

Five minutes to your first flag

  1. In Flagsmith, create a flag called run_speed with the value 7.
  2. Open your environment's SDK keys page and copy the client-side environment key.
  3. Add a FlagsmithBehaviour component to a GameObject in your first scene and paste the key. Leave the API URL as it is for Flagsmith Cloud, or set it to http://your-host:8000/api/v1/ for self-hosted.
  4. Bind a field to the flag:
using Flagsmith;
using UnityEngine;

public class Player : MonoBehaviour
{
    [SerializeField] FlagsmithBehaviour flagsmith;

    [FlagsmithValue("run_speed")] float runSpeed = 7f;   // 7 until the first fetch, and offline

    void Awake() => flagsmith.Bind(this);
}
  1. Press Play, change run_speed in Flagsmith, and the field follows on the next refresh.

Package Manager also has a Quickstart sample: select the package, then Samples > Import.