Unity.Multiplayer/rfc/0001-architecture
RFC 0001 — Architecture and build order
Approved 2026-10-20. Ticket IDs below are the real workflow IDs; the chain is enforced by
requireslinks (workflow ticket show <ID>).
Context
Cursory is a co-op physics puzzle game. The server owns the game (CUR-LAW-1), and it runs as ASP.NET Blazor Server with SignalR and Aether.Physics2D. Players drag blocks together, and a block heavier than 1.5 mass units needs two cursors. It has 14 levels, votes, whistles and a circuit puzzle. Ryan wants that gameplay in Unity 6 (6000.4.3f1, the workspace's version) with full multiplayer in two forms:
- dedicated server (hub-and-spoke): everyone joins a central headless server
- listen server: one player hosts
Players join by IP:port or a join code.
The main goal is a multiplayer layer that is reusable in any game with minimal effort. That layer is a new repo, Unity.Multiplayer, built around attribute-decorated RPCs, with full docs and a docs website. All work is filed as chained workflow tickets, so it can only be built in the right order.
What exploration found:
- MindAttic.Unity has no code. Its design exists only as ticket MAU-T2, which sets the family conventions:
- a local
file:../../package - an engine-free Core asmdef tested by plain
dotnet testwith NUnit - a thin Runtime asmdef
- a local
- Packaging precedent: the Capture and Telemetry packages use the
unity/com.mindattic.<x>/layout. - No Unity project uses networking or CI.
- No repo has a docs site. README-STYLE.md makes the README the project page, so DocFX is new ground.
- Workflow tooling:
workflow ticket link A requires Bgives hard ordering, andrepos rollout ticketsassigns a code to a new repo.
Decisions (confirmed by the owner)
- Netcode for GameObjects 2.x and Unity Transport, hidden behind MindAttic's own API. NGO is the only backend for now; nothing above the adapter references NGO.
- Join codes: one
IJoinCodeServiceinterface, two implementations:- Unity Relay: gets through NAT, so it is the default for listen servers
- a self-hosted rendezvous service that maps a code to IP:port, the default for dedicated servers
- Docs: DocFX, published to GitHub Pages at
mindattic.github.io/Unity.Multiplayer. The README still follows README-STYLE. - Approving this plan approves every ticket below (
orchestrator approve). Therequireslinks stop work from starting out of order.
Architecture
Unity.Multiplayer (public, MIT)
unity/com.mindattic.unity.multiplayer/ package.json (unity 6000.0; deps netcode.gameobjects 2.x,
transport 2.x; services.multiplayer optional via versionDefines)
Runtime/Core/ Unity.Multiplayer.Core.asmdef (noEngineReferences, netstandard2.1)
SessionStateMachine, JoinCode format, NetConfig, ITickClock, attributes
([ToServer]/[ToClients]/[ToOwner]/[ToClient]/[Synced]), approval payload,
protocol-hash contract, SeatRegistry + ConnectionAdmission (engine-free seat
rules), rendezvous wire protocol + client (RendezvousClient,
RendezvousJoinCodeService, ServerAdvertisement)
Runtime/ Unity.Multiplayer.asmdef (NGO adapter)
NetSession (StartHost/StartServer/JoinByAddress/JoinByCode/Leave), NetEntity
(non-generic NetworkBehaviour base), NetSender, transports (UDP | WebSocket),
RelayJoinCodeService, ConnectionApproval
(version + protocol hash + player token), seats (reconnect → same seat and
player object, over Core's SeatRegistry),
NetworkTickClock, server-driven scene flow, per-sender rate limiter,
headless bootstrap (-batchmode, targetFrameRate=tick), NetBootstrap component
Runtime/Generators/ Unity.Multiplayer.Generators.dll (RoslynAnalyzer label)
Editor/ setup wizard (MindAttic ▸ Multiplayer ▸ Set Up Scene), prefab validator,
"Build Dedicated Server (Linux)" menu
Tests/Runtime/ NetcodeIntegrationTest PlayMode suites (NGO in manifest "testables")
Samples~/ Minimal (host/join/code UI, one [ToServer], one [Synced], one [ToClients])
src/Generators/ IIncrementalGenerator, netstandard2.0, Microsoft.CodeAnalysis.CSharp 4.3.x, emits C# 9 only
server/Rendezvous/ ASP.NET Core .NET 10 minimal API + Dockerfile (register/heartbeat/resolve,
TTL, high-entropy codes, per-IP rate limit, registration secret)
tests/ Core.Tests (net10 NUnit, globs Runtime/Core), Generators.Tests, Rendezvous.Tests
docs/ DocFX: docfx.json, articles/ (guides), api/ (from XML docs); BIBLE.md, USER_STORIES.md
.github/workflows/ docs.yml (Pages), ci.yml (dotnet tests + GameCI PlayMode)
Attribute API: what a game writes
public partial class CursorAvatar : NetEntity
{
[ToServer(Delivery = Delivery.Unreliable, RateLimit = 30)]
public partial void Move(Vector2 worldPos); // call site: Move(p)
void OnMove(Vector2 worldPos, NetSender sender) { ... } // runs on server
[ToClients] public partial void Whistle(Color c);
void OnWhistle(Color c) { ... } // runs on every client
[Synced(OnChanged = nameof(MassChanged))] float _mass; // generator emits NetworkVariable + Mass property
}
- How it works: these are C# 9 extended partial methods. The generator writes the sending body and the matching NGO
...Rpcstub, which applies ownership checks, rate limiting and the sender, then callsOn<Name>. - If generation fails, the build stops with "partial method has no implementation" instead of failing silently.
- Analyzer errors for:
- generic
NetEntitysubclasses - parameter types that can't be serialized
- direct writes to a
[Synced]backing field - a missing
On<Name>handler
- generic
- Protocol hash: the generator emits one hash of every RPC and Synced signature. Connection approval rejects a mismatch with a clear reason.
- Fallback if the spike shows ILPP problems: hand-written stubs shaped exactly like the generator output. Not reflection.
Hosting
The hosting provider is undecided (owner, 2026-10-20) and will be chosen later. The design keeps it open: UM-T23 adds IHostingProfile and a provider-neutral server package. That package is a self-contained Linux build with server.json plus command-line overrides, declared ports, Logs/, Saves/, clean shutdown on SIGTERM and a health endpoint. Every host gets the same package, so choosing one later changes no game code.
- GenericVps: the first profile built. It runs the Docker image plus the rendezvous container on a UDP-capable CPU VPS (Hetzner, Vultr, DigitalOcean and similar).
- RunPod: pods appear to expose TCP/HTTP only, so this profile uses
UseWebSockets=trueand registers its mappedRUNPOD_TCP_PORT_*with the rendezvous service. UM-T18 verifies RunPod's current UDP support first. - Later, possibly: G-Portal (not a default; reachable only through its Private Server program for studios), Nitrado, Edgegap and GameLift. Each would plug in as a new profile.
The owner's home network allows no port forwarding (an HOA-controlled network). That has three consequences:
- A listen server hosted from home must use Relay join codes.
- Join by IP from home works on the LAN only.
- Internet play by IP needs a dedicated server on a rented host.
The self-hosted rendezvous service maps codes to addresses but cannot get through NAT, so it is for dedicated servers only. Development needs no port forwarding: localhost, LAN, Multiplayer Play Mode and Relay all work behind NAT.
UnityCursory (public)
Unity 6 2D top-down with URP 2D and an orthographic camera.
Server simulation:
- Runs on the server only.
Physics2D.simulationMode = Script, stepped at 1/30 s fromNetworkTickSystem.Tick(TickRate 30).- Clients never simulate.
Mapping from Cursory (constants from Cursory.Core/Services/RoomState.cs:49-119):
- Grab:
FixedMouseJointbecomesTargetJoint2D(maxForce 60, frequency 5, damping 0.7, autoConfigureTarget off). - Ground friction: the Aether friction joint becomes
FrictionJoint2Dwith no connected body (maxForce Mass×40, maxTorque ×1.2). - Bodies:
rb.mass = Mass×5, gravity 0, linear damping 1.5, angular damping 2.0. - Units: keep 100 px per metre.
These values keep "mass > 1.5 needs two players" intact. Level masses stay clear of 1.5 and 3.0.
Syncing:
- Server-authoritative NetworkTransform plus NetworkRigidbody2D, syncing x, y and rotation z only.
- Half precision, interpolated.
- Hidden behind an
IBodySyncinterface, so a compact snapshot can replace it later.
Content and features:
- Levels become ScriptableObjects, one per level, ported from
SeedLevel1..14. - Votes use a 2/3 quorum with a 15 s timeout, and early rejection when the vote can no longer pass.
- Whistles, the circuit puzzle, the HUD, the pause menu and the minimap all carry over.
- The cursor is the player object.
- The player's name and color come from the MindAttic.Unity profile (MAU-T2), which replaces Cursory's cookie accounts.
- The cursor-collision and segmented-tether toggles become per-player settings, fixing Cursory's README/code mismatch.
- Out of scope: Cursory's dead
SwitchTile/Doortypes.
Execution (Step 0 done 2026-10-20 under MAT-T7, UM-T2, UC-T2)
Step 0: bootstrap (done by me right after approval, one MindAttic.Toolkit chore ticket)
gh repo create mindattic/MindAttic.Unity.Multiplayer --publicandmindattic/UnityCursory --public.- Run
mindattic-agent-standard/clone-repo.ps1 -Repo <name>for each. This clones the repo, tags itwipand restarts the Launcher. workflow repos rollout tickets --apply, which assigns each repo its code and USER_STORIES.md.install-commit-hooks.ps1.- Add AGENTS.md/CLAUDE.md forwarders like the sibling repos.
- File every ticket below with
workflow ticket new, chain them withworkflow ticket link <later> requires <earlier>, then runorchestrator approveon each. - Print the resulting ID map.
Ticket chain
Each ticket requires the one before it unless it notes otherwise. "MP" means the multiplayer repo and "UC" means UnityCursory; the real IDs are assigned at filing.
Unity.Multiplayer
- UM-T3 (chore) Repo skeleton:
- package.json and asmdefs
- LICENSE (MIT), .gitattributes (LF, HOUSE-LAW-13), README stub
- docs/BIBLE.md with the laws: server owns state; nothing above the adapter imports NGO; generator output is C# 9
- UM-T4 (feature) Spike: a throwaway Unity project with one hand-written
[Rpc]emitted through a toy generator, one NetworkVariable, a host and one client, and an IL2CPP Linux server build. It records go or fallback in an RFC. This is the gate for UM-T11. - UM-T5 (feature) Core: NetConfig, the session state machine, and the
ITickClockcontract, with dotnet NUnit tests. - UM-T6 (feature) Core: the join-code format (high entropy, unambiguous alphabet, checksum) and the
IJoinCodeServicecontract, with tests. - UM-T7 (feature) Core: the approval payload (game version, protocol hash, player token) and its validation, with tests.
- UM-T8 (feature) Runtime:
- the NGO adapter
- NetSession with StartHost, StartServer, JoinByAddress and Leave
- UDP and WebSocket transport selection
- NetworkTickClock
- the headless bootstrap
- PlayMode tests: host+client, then server+2 clients
- UM-T9 (feature) Runtime:
- ConnectionApproval
- SeatRegistry, so a reconnecting player gets the same seat
- disconnect reasons
- PlayMode tests for mismatch rejection and reconnect
- UM-T10 (feature) Runtime: NetEntity, NetSender, the per-sender rate limiter, and server-driven scene flow. The RPC stubs are hand-written in the exact shape the generator will emit.
- UM-T11 (feature) Generator:
- partial-method RPCs for all four directions
[Synced]fields- protocol hash
- analyzer diagnostics
- Generators.Tests snapshot tests
- UM-T10's hand-written stubs replaced by generated ones, with the PlayMode tests unchanged and still green
- Requires UM-T4 and UM-T10.
- UM-T12 (feature) The rendezvous server (.NET 10 minimal API, Dockerfile) with Rendezvous.Tests.
- UM-T13 (feature) RendezvousJoinCodeService (client, plus the dedicated server's self-registration) and RelayJoinCodeService. Adds
JoinByCode, with a PlayMode test against an in-process rendezvous server. - UM-T14 (feature) A latency and loss simulation profile, plus a lossy PlayMode suite.
- UM-T15 (feature) Editor: the setup wizard, the prefab validator, and the Build Dedicated Server menu.
- UM-T16 (feature) The Minimal sample in Samples~.
- UM-T17 (chore) CI with
ci.yml: dotnet tests and the GameCI PlayMode run, plus a nightly Docker Compose smoke test (server plus 2 headless bot clients). This needs a Unity license secret, which Ryan supplies. - UM-T18 (docs) Hosting guide: one section per hosting profile (GenericVps, RunPod), how to pick one, and the no-port-forwarding path (Relay for home hosting). Includes checking RunPod's current UDP support. Requires UM-T23.
- UM-T19 (docs) DocFX site:
- guides: Getting Started in 10 minutes, Topologies, Attributes reference, Join codes, Reconnect and seats, Testing, Hosting, Porting a game, Troubleshooting
- API reference generated from XML docs
- published to GitHub Pages by
docs.yml - README rewritten to README-STYLE, linking the site
- UM-T20 (chore) Tag v1.0.0. Release notes.
- UM-T23 (feature) Server package + hosting profiles (see Hosting). Requires UM-T15. UM-T18 and UC-T13 require it.
UnityCursory (UC-T3 requires UM-T10, so early porting can start before the generator lands. UC-T7 requires UM-T20, library v1.0.0; UC-T12 requires MAU-T2, MindAttic.Unity profiles; UC-T15 requires UM-T19, the DocFX site.)
- UC-T3 (chore) Unity 6000.4.3f1 project:
- URP 2D
- manifest referencing
file:../../MindAttic.Unity.Multiplayer/unity/com.mindattic.unity.multiplayerand Capture - the
Tests/Core.Testsdotnet pattern - BIBLE.md that ports the CUR-LAW rules
- .gitattributes
- UC-T4 (feature) The engine-free Core model, ported from
GameState.cs: blocks, shapes, walls, goals, circuit, votes, whistles, plus the level data schema. Includes NUnit tests. - UC-T5 (feature) Level ScriptableObjects for L1–L14 ported from
SeedLevelN, plus SolvabilityTests ported from Cursory.Tests. - UC-T6 (feature) Server physics sim: Script mode at 30 Hz, the friction and grab joint mapping, mass/inertia/damping. PlayMode test: one cursor moves mass 1.0 but not 2.0; two cursors move 2.0.
- UC-T7 (feature) Networked cursor as the player object.
[ToServer]Move/Grab/GrabShape/GrabWall/GrabWireEnd/Release, server-authoritative body sync, interpolation. - UC-T8 (feature) Tethers, the segmented rope and cursor collision, as per-player settings.
- UC-T9 (feature) Goals and win detection (block and shape), plus the circuit bulb logic, ported with CircuitTests.
- UC-T10 (feature) Votes (reset and level, 2/3 quorum, early reject, 15 s timeout) and whistles.
- UC-T11 (feature) Client presentation: camera pan and zoom (0.1–4), click-vs-drag thresholds, the HUD, vote overlay, level banner, pause menu and minimap, with synthesized whistle tones.
- UC-T12 (feature) Front end: the profile name and color (MindAttic.Unity), Host / Join by IP / Join by code / Quit, and the join-code display for the host.
- UC-T13 (feature) The dedicated server build and Docker image for the server plus rendezvous, deployed per UM-T18.
- UC-T14 (chore) An end-to-end test: server plus 2 headless bots solve L2 together.
- UC-T15 (docs) README to README-STYLE with screenshots, a "how it uses the library" page linked from the DocFX "Porting a game" guide, and a v1.0.0 tag.
Every commit names its own ticket (the commit-msg hook enforces this). Each ticket is one commit, on main.
Verification
- Core:
dotnet teston Core.Tests, Generators.Tests and Rendezvous.Tests in each repo. - Unity: PlayMode runs of NetcodeIntegrationTest suites in both topologies (host+client, server+2 clients), including the lossy profile, through the Unity CLI with
-runTests -batchmodeand in CI. - Smoke test: the nightly Docker Compose run, where the Linux server build and 2 bot clients connect by join code and exchange RPCs.
- Manual:
- Multiplayer Play Mode with 2 or 3 virtual players: host by code, join by IP, then kill a client and reconnect to confirm it gets the same cursor back.
- On a real VPS: a dedicated server joined from two machines.
- Docs: the DocFX site builds without warnings, and the Pages URL loads.