mcpField
S
spacetimedb-client-c-sharp

spacetimedb-client-c-sharp

github.com/danmossaDevelopment2152 installsUpdated 19w ago
Repository

About spacetimedb-client-c-sharp

A skill for implementing C# and Unity clients with SpacetimeDB, covering generated bindings, connection handling, subscriptions, and runtime rules. It helps developers use project-generated APIs while keeping Unity lifecycle code separate from generated code.

Key features

  1. 01Generate C# client bindings
  2. 02Configure connections and subscriptions
  3. 03Read subscribed rows and handle events
  4. 04Invoke reducers and register callbacks
  5. 05Follow Unity runtime and threading rules

Use cases

  1. 01Building a SpacetimeDB C# client
  2. 02Connecting a Unity project to a database
  3. 03Reading table updates and invoking reducers

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/danmossa/spacetimedb-skills --skill spacetimedb-client-c-sharp

After installing, type/spacetimedb-client-c-sharpin Claude Code to confirm it loaded.

Bundled filesreferences/clients-c-sharp.md

Details

From the project README

Use this skill for C# and Unity client implementation.

Core C# patterns

Generate C# bindings and use the generated DbConnection, RemoteTables, and RemoteReducers names from the user's project:

spacetime generate --lang csharp --out-dir client/module_bindings --module-path spacetimedb
var conn = DbConnection.Builder()
    .WithUri(new Uri("ws://localhost:3000"))
    .WithDatabaseName("my-database")
    .OnConnect((conn, identity, token) =>
    {
        conn.SubscriptionBuilder().SubscribeToAllTables();
    })
    .OnConnectError((ctx, err) => Log.Error(err.ToString()))
    .OnDisconnect((ctx, err) => Log.Info("Disconnected"))
    .Build();

Runtime rules

  • Call conn.FrameTick() from the main loop or Unity update path; callbacks and cache updates will not be applied otherwise.
  • Do not run FrameTick() on a background thread while main-thread code reads conn.Db.
  • Read subscribed rows through conn.Db.<Table>.Iter(), Count, and generated unique/index handles.
  • Register table events with OnInsert, OnDelete, and OnUpdate; OnUpdate requires a primary key.
  • Invoke reducers through conn.Reducers.<ReducerName>(...) and register generated reducer events when needed.
  • Keep Unity lifecycle code in MonoBehaviours or service classes and leave generated bindings unedited.

Reference map

NeedOpen
C# SDK APIreferences/clients-c-sharp.md

Guidance

  • Use the generated C# binding names from the user's project when available.
  • Keep Unity lifecycle code separate from generated binding code unless the project already combines them.
  • Route full Unity tutorial work to spacetimedb-tutorials.

Comments

Markdown supported