Integrate SpacetimeDB with Unity game projects. Use when building Unity clients with MonoBehaviour lifecycle, FrameTick, and PlayerPrefs token persistence.
This skill covers Unity-specific patterns for connecting to SpacetimeDB. For server-side module development and general C# SDK usage, see the spacetimedb-csharp skill.
// WRONG — these do not exist in Unity SDK
SpacetimeDBClient.instance.Connect(...); // Use DbConnection.Builder()
SpacetimeDBClient.instance.Subscribe(...); // Use conn.SubscriptionBuilder()
NetworkManager.RegisterReducer(...); // SpacetimeDB is not a Unity networking plugin
// WRONG — old 1.0 patterns
.WithModuleName("my-db") // Use .WithDatabaseName() (2.0)
ScheduleAt.Time(futureTime) // Use new ScheduleAt.Time(futureTime)
| Wrong | Right | Error |
|---|
Not calling FrameTick() | conn?.FrameTick() in Update() | No callbacks fire |
Accessing conn.Db from background thread | Copy data in callback, use on main thread | Data races / crashes |
Forgetting DontDestroyOnLoad | Add to manager Awake() | Connection lost on scene load |
Connecting in Update() | Connect in Start() or on user action | Reconnects every frame |
| Not saving auth token | PlayerPrefs.SetString(...) in OnConnect | New identity every session |
| Missing generated bindings | Run spacetime generate --lang csharp | Compile errors |
Add via Unity Package Manager using the git URL: