What problem does it solve?
This Skill provides Unity-specific patterns and lifecycle guidance to correctly connect, maintain, and use SpacetimeDB in Unity projects, preventing common issues like missed callbacks, thread-safety violations, lost connections on scene load, and token loss.
Core Features & Use Cases
- Connection lifecycle management: Use a SpacetimeManager MonoBehaviour singleton with DontDestroyOnLoad, Awake/Start/OnDestroy hooks, and proper OnConnect/OnDisconnect handling.
- Frame-driven networking: Ensure Connection.FrameTick() is invoked from Update() on the main thread so queued network messages are processed and callbacks fire.
- Subscriptions, reducers, and client cache: Generate C# module bindings, subscribe to tables, register OnInsert/OnUpdate/OnDelete handlers, call reducers from UI, and persist auth tokens with PlayerPrefs for seamless reconnects.
- Use Case: Real-time multiplayer game state synchronization and chat where deterministic main-thread processing and token persistence are required.
Quick Start
Create a SpacetimeManager MonoBehaviour that builds a DbConnection with WithUri and WithDatabaseName, persists the auth token to PlayerPrefs in OnConnected, and calls Connection.FrameTick() from Update().