Jump to content

Unity.Multiplayer: Difference between revisions

From MindAttic Docs
md2wiki: sync from MindAttic.Docs
md2wiki: sync from MindAttic.Docs
 
(2 intermediate revisions by the same user not shown)
Line 173: Line 173:


<strong>v1.0.0</strong> is tagged and released (UM-T20). <strong>v2.0.0</strong> (UM-T59) adds the drop-in front end, the roster, votes, keyed objects, bots, the test kit, <code>mp-host game</code> and the New Game wizard: everything the kit needs to be a one-stop shop. See CHANGELOG.md for everything that shipped and the [https://github.com/mindattic/Unity.Multiplayer/releases GitHub releases page] for the releases themselves.
<strong>v1.0.0</strong> is tagged and released (UM-T20). <strong>v2.0.0</strong> (UM-T59) adds the drop-in front end, the roster, votes, keyed objects, bots, the test kit, <code>mp-host game</code> and the New Game wizard: everything the kit needs to be a one-stop shop. See CHANGELOG.md for everything that shipped and the [https://github.com/mindattic/Unity.Multiplayer/releases GitHub releases page] for the releases themselves.
== Scope ==
The complete kit, every epic, feature and story with what is built, is in [[Unity.Multiplayer/SPEC|SPEC.md]]. The current finish line, MS-37 "Unity.Multiplayer 3: the Relay release its games build on", is in [[Unity.Multiplayer/RELEASE|RELEASE.md]]; release 3 finishes the kit.


== Documentation ==
== Documentation ==
Line 230: Line 234:
* [[Unity.Multiplayer/rfc/0001-architecture|rfc/0001-architecture]] — 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…
* [[Unity.Multiplayer/rfc/0001-architecture|rfc/0001-architecture]] — 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…
* [[Unity.Multiplayer/rfc/0002-generator-spike|rfc/0002-generator-spike]] — Can a Roslyn IIncrementalGenerator turn a C# 9 extended partial method into an NGO [Rpc(SendTo.Server)] stub, and a marked field into a…
* [[Unity.Multiplayer/rfc/0002-generator-spike|rfc/0002-generator-spike]] — Can a Roslyn IIncrementalGenerator turn a C# 9 extended partial method into an NGO [Rpc(SendTo.Server)] stub, and a marked field into a…
* [[Unity.Multiplayer/SPEC|Unity.Multiplayer — Product specification]] — Place in the ecosystem: An engine kit (docs/ECOSYSTEM.md §2.1): the netcode every MindAttic Unity game uses.


<div class="md2wiki-source">From [https://github.com/mindattic/Unity.Multiplayer/blob/main/README.md Unity.Multiplayer/README.md] via MindAttic.Docs; synced automatically, so edit the repo, not this page.</div>
<div class="md2wiki-source">From [https://github.com/mindattic/Unity.Multiplayer/blob/main/docs/overview.md Unity.Multiplayer/docs/overview.md] via MindAttic.Docs; synced automatically, so edit the repo, not this page.</div>


[[Category:Unity.Multiplayer]]
[[Category:Unity.Multiplayer]]

Latest revision as of 19:45, 30 November 2026

Unity.Multiplayer

The one-stop shop for multiplayer Unity 6 games. With its two sibling packages, MindAttic Components (the menus and HUD) and Unity.Shared (player profiles), it is one kit that covers the whole game: attribute-decorated RPCs and synced fields, a listen server or a dedicated server from the same code, joining by IP:port or a short join code, menus, player names and colours, votes, objects found by key, bots, a test kit, and one command to build, deploy and smoke-test a server. MindAttic ▸ Multiplayer ▸ New Game… turns an empty Unity project into a working networked game in minutes.

unity-6000.4-black.svg netcode-2.x-blue.svg dotnet-10-512BD4.svg license-MIT-brightgreen.svg status-v2.0.0-brightgreen.svg

Package What it gives a game
Unity.Multiplayer (com.mindattic.unity.multiplayer, this repo) Networking, roster, votes, keyed objects, bots, the test kit, the server package and mp-host
MindAttic Components (com.mindattic.components.unity) The drop-in menus and vote overlay, and the widgets for your own HUD
Unity.Shared (com.mindattic.unity.shared) The player's name and colour (and settings) from their MindAttic profile

See The kit for which piece does which job, and Case study: Unity.Cursory for a full game built on all three.

The whole networked surface of a game object is usually three declarations:

public partial class MinimalPlayer : NetEntity
{
    [ToServer(RateLimit = 20)]
    public partial void SetDirection(Vector2 direction);

    [ToClients]
    public partial void Bumped();

    [Synced] private Vector2 _position;
}

Try it: the full docs site, with a 10-minute getting-started guide, every attribute's rules, and the complete hosting story, is at mindattic.github.io/Unity.Multiplayer.

Status: v2.0.0, the one-stop shop release (the New Game wizard and template, the kit docs). See Roadmap below for what's built, and CHANGELOG.md for what shipped in each release. The design and build order are in docs/rfc/0001-architecture.md; the rules are in docs/BIBLE.md.

Why

  • Start a new multiplayer game from a working one: menus, roster, votes, keyed objects, a bot, tests and a deploy config from one wizard, all built from the kit's own pieces, not a demo to throw away.
  • Network a new game object in three attributes, not a day of hand-rolled NetworkVariables and RPCs.
  • Ship a listen server for tonight's game and a dedicated server for a persistent world from the same game code — the topology is one setting, never a fork.
  • A player who disconnects gets the same seat and the same player object back if they reconnect within a minute, with no special-casing in game code.
  • Players join by typing a short, typo-tolerant code, whether the host is behind a home router (Unity Relay) or a dedicated box you rented (the self-hosted rendezvous service).
  • An ownership mistake, a missing handler or a bad RPC shape is a compile error from the package's own source generator and analyzer, never a runtime surprise.
  • One mp-host CLI and one server package deploy to fifteen-plus hosting providers, from a $4 VPS to AWS GameLift, without a hand-written Dockerfile per host.

Features

  • New Game wizard — MindAttic ▸ Multiplayer ▸ New Game… checks Packages/manifest.json and names (or adds) the exact lines the kit needs, then makes Assets/<YourGame>: a scene with NetBootstrap, NetFrontEnd and NetVotes; a player with a [ToServer] move and a [Synced] position in its roster name and colour; crates spawned by key; a restart vote; an IBotDriver; EditMode and PlayMode tests on the test kit; and mp-host.json plus a nightly smoke workflow. See Getting started.
  • Attribute RPCs and synced state — [ToServer], [ToClients], [ToOwner], [ToClient], [Synced], with per-RPC rate limiting, ownership checks and a change handler, all generated at compile time. See Attributes reference.
  • Objects found by name — a NetKey on a prefab and a key from the server ("block:12", "door:A"), and every peer finds that object with NetSession.Objects.TryGet(key, out T), late joiners included, whatever order things spawned in. See Networked objects by key.
  • Any topology, same code — listen server, dedicated server or client from one NetConfig. See Topologies.
  • Join codes and reconnect — Unity Relay or a self-hosted rendezvous service behind one interface, and seats that survive a drop. See Join codes and Reconnect and seats.
  • Drop-in front end — one NetFrontEnd component (MindAttic ▸ Multiplayer ▸ Add Front End) gives any game a main menu (Host, Join by IP, Join by code, Settings), a lobby with the join code and roster, connection dialogs in plain words, automatic reconnect to the same seat and an in-game Esc menu, built from MindAttic Components and optional. See Drop-in front end.
  • Votes — restart, change-level, kick or any vote a game defines: one NetVotes component, a VoteKind per vote with its effect on the server, two-thirds quorum, timeouts and early rejection, and a ready-made overlay with the front end. See Votes.
  • Editor tooling — one-click scene setup, a prefab validator, and a Linux Dedicated Server build, all from the MindAttic ▸ Multiplayer menu.
  • A hosting pipeline — the same server package deploys to any GenericVps-shaped host, RunPod, or a per-match allocator (Edgegap, Gameye, AWS GameLift) through one mp-host CLI. See Hosting.
  • Bad-connection testing — simulate latency, jitter and packet loss per peer, in the editor or a development build, without touching the network.

Quick start

Prerequisites: Unity 6000.4.3f1, and the kit's three repos cloned side by side with your game's folder:

git clone https://github.com/mindattic/Unity.Multiplayer
git clone https://github.com/mindattic/MindAttic.Components
git clone https://github.com/mindattic/Unity.Shared

Add the package to the game's Packages/manifest.json as a local package (the package alone compiles; to use its test kit also list Netcode for GameObjects as a testable, see Testing):

"dependencies": {
  "com.mindattic.unity.multiplayer": "file:../../Unity.Multiplayer/unity/com.mindattic.unity.multiplayer",
  ...
}

It pulls in Netcode for GameObjects 2.x and Unity Transport 2.x. For Unity Relay join codes, which let a player host from home with no port forwarding, add com.unity.services.multiplayer and link the project to a Unity Cloud project. The New Game wizard's step 3 or tools/link-unity-cloud.ps1 does both; see Join codes.

A new game: run MindAttic ▸ Multiplayer ▸ New Game…, click Add missing lines to Packages/manifest.json, type a name and click Create game, then open its Game.unity, press Play and click Host. That is a whole game with menus, votes, a bot and tests; mp-host game local runs its dedicated server in Docker and mp-host game smoke runs it with two bots. Getting started walks through every step and every file.

Just the samples: in Window > Package Manager, select MindAttic Multiplayer, open Samples and import Minimal. Open its Minimal.unity scene, press Play and click Host; a second copy (Multiplayer Play Mode, or a build) clicks Join by IP or Join by code. Each player's square is moved by the server through one [ToServer] call, one [ToClients] call and one [Synced] field — the sample's own README walks through every line, and the docs site's Getting started in 10 minutes covers the same ground with more detail.

For your own scene with menus in two minutes: add MindAttic Components (and optionally Unity.Shared, for the player's profile name and colour) to the manifest, run MindAttic ▸ Multiplayer ▸ Add Front End and press Play — the Front End sample is that, done. See Drop-in front end.

Without the menus: run MindAttic ▸ Multiplayer ▸ Set Up Scene, give your player prefab a NetworkObject and a partial class deriving from NetEntity, mark methods and fields with the attributes above, and run MindAttic ▸ Multiplayer ▸ Validate Prefabs before you ship. See Porting a game for moving an existing project onto the package.

Project layout

Path What
unity/com.mindattic.unity.multiplayer/ The Unity package (package.json, Runtime, Editor, Tests); Runtime/Generators/ holds the built generator DLL
unity/com.mindattic.unity.multiplayer/Runtime/UI/ The optional drop-in front end (Unity.Multiplayer.UI, compiled only when MindAttic Components is installed)
unity/com.mindattic.unity.multiplayer/Samples~/Minimal/ The Minimal sample Package Manager imports (scene, player prefab, menu, line-by-line README)
unity/com.mindattic.unity.multiplayer/Samples~/FrontEnd/ The Front End sample: the same arena with the drop-in front end and its game hooks
unity/com.mindattic.unity.multiplayer/Samples~/GameTemplate/ The game template New Game… copies (Editor/Setup/NewGame*.cs): scene, player, keyed crates, votes, bot, tests
src/Generators/ The source generator, analyzers and suppressor (netstandard2.0, Roslyn 4.3.1)
src/Hosting.Cli/ mp-host: builds a server package and deploys it to any hosting profile
server/Rendezvous/ The rendezvous service (ASP.NET Core .NET 10 minimal API + Dockerfile): join code to a dedicated server's IP:port
tests/ Core.Tests, Generators.Tests, Rendezvous.Tests, Hosting.Cli.Tests (plain dotnet test); Core.Build compiles Core the way Unity does; PlayModeHost, MinimalSample and FrontEndSample run the Unity PlayMode/EditMode suites
smoke/ The package's own nightly Docker Compose smoke test: rendezvous, a dedicated server and two headless bot clients joining by code (games use mp-host game smoke, see Bots)
docs/ DocFX site (docfx.json, articles/), BIBLE, RFCs, user stories

Run a dedicated server

Add a NetBootstrap to the NetworkManager's GameObject. A headless launch serves by itself:

Game.x86_64 -batchmode -nographics -port 7777 -transport udp

-mode host|server|client, -address, -tickrate, -maxplayers, -name and -password are read too. MindAttic ▸ Multiplayer ▸ Build Dedicated Server (Linux) makes that build and writes its Dockerfile. MindAttic ▸ Multiplayer ▸ Build Server Package adds server.json, start.sh, a health endpoint and per-profile hosting files into Builds/ServerPackage/<profile>/. To build and run it with no script of your own, install mp-host once (powershell -File tools/install-mp-host.ps1, a .NET tool) and, in the Unity project, run mp-host game local (this PC, Docker) or mp-host game deploy --profile <GenericVps|RunPod|...>; it finds the editor from ProjectVersion.txt and the server scene from Build Settings. Full detail, every setting and every hosting provider: Topologies and Hosting on the docs site.

Run the rendezvous service

A dedicated server registers its public IP:port and gets a join code; players resolve the code to connect.

docker build -f server/Rendezvous/Dockerfile -t mindattic-rendezvous .
docker run -p 8080:8080 -e Rendezvous__RegistrationSecret=<secret> mindattic-rendezvous

It will not start without a registration secret (Rendezvous__AllowOpenRegistration=true is for local development only). See Join codes for the full protocol, TLS and secrets.

On Windows without Docker, run.bat (or .\run.ps1) opens the shared run menu for it: 1 Redeploy builds it into R:\MindAttic\Apps\Unity.Multiplayer\{Debug,Release}, 2 Run Debug and 3 Run Release start it; 13 is Deploy & Run.

Test on a bad connection

NetConfig.Conditions (or the Net Bootstrap's Inspector fields, or -netsim) makes this peer's link slow and lossy: Broadband, Mobile4G, Mobile3G, Lossy or Custom (-latency 150 -jitter 10 -loss 5). Editor and development builds only. Details: Topologies § Testing a bad connection.

Test

dotnet test tests/Core.Tests
dotnet test tests/Rendezvous.Tests
dotnet test tests/Generators.Tests          # UPDATE_SNAPSHOTS=1 rewrites Snapshots/ after an intended change
dotnet test tests/Hosting.Cli.Tests
powershell -File tests/run-playmode.ps1     # PlayMode suite in Unity 6000.4.3f1 batch mode
powershell -File tests/run-editmode.ps1     # EditMode suite (editor tooling, one real Linux server build; -SkipBuild leaves it out)
powershell -File tests/run-sample.ps1       # imports the Minimal sample through Package Manager and runs its PlayMode tests (-Author rebuilds its scene and prefabs)
powershell -File tests/run-sample.ps1 -Sample FrontEnd   # the same for the Front End sample (needs the sibling MindAttic.Components and Unity.Shared repos)
powershell -File tests/run-new-game.ps1     # a brand-new project in %TEMP%: New Game's manifest check, create, the game's EditMode + PlayMode tests (-Smoke adds mp-host game smoke; -Author rebuilds the template's scene and prefabs)
powershell -File tests/run-smoke.ps1        # builds the nightly smoke test's Linux player (server + 2 bots, same build, role picked by MINDATTIC_ROLE)

CI (.github/workflows/ci.yml) runs the dotnet test suites and the PlayMode/EditMode suites through GameCI's unity-test-runner, and needs a UNITY_LICENSE repository secret: run powershell -File tools\set-ci-secrets.ps1 to set it and the other CI secrets (see CI secrets). A nightly job (.github/workflows/nightly-smoke.yml) runs the Docker Compose smoke test above end to end. .github/workflows/docs.yml publishes the docs site. See Testing for what each suite covers.

After changing src/Generators, run dotnet build src/Generators -c Release. It copies the DLL into Runtime/Generators/, where Unity loads it; commit that DLL along with the source change.

Roadmap

Built and verified (each backed by a test suite — see docs/BIBLE.md for exactly which one): session and config, join codes, connection approval and seats, the NGO adapter and headless bootstrap, every RPC direction and synced fields, the source generator and its analyzer, the rendezvous service, network condition simulation, the editor tooling, the Minimal sample, CI and the nightly smoke test, the full hosting pipeline (mp-host plus every provider's profile), and this docs site.

v1.0.0 is tagged and released (UM-T20). v2.0.0 (UM-T59) adds the drop-in front end, the roster, votes, keyed objects, bots, the test kit, mp-host game and the New Game wizard: everything the kit needs to be a one-stop shop. See CHANGELOG.md for everything that shipped and the GitHub releases page for the releases themselves.

Scope

The complete kit, every epic, feature and story with what is built, is in SPEC.md. The current finish line, MS-37 "Unity.Multiplayer 3: the Relay release its games build on", is in RELEASE.md; release 3 finishes the kit.

Documentation

  • Docs site — guides (getting started, the kit, the Unity.Cursory case study, front end, players, votes, objects, topologies, attributes, join codes, reconnect and seats, testing, bots, hosting, porting, troubleshooting) and the API reference generated from this repo's XML doc comments.
  • CHANGELOG.md — what shipped in each release.
  • docs/BIBLE.md — the project's rules and verified state.
  • docs/rfc/0001-architecture.md — the design and build order.
  • docs/USER_STORIES.md — every ticket and its status.
  • AGENTS.md — agent and contributor instructions for working in this repo.

License

MIT. See LICENSE.

Part of MindAttic — see more projects at github.com/mindattic. Related: Unity.Cursory (the first game built on this package), Unity.Shared (player profiles every MindAttic Unity game shares) and MindAttic.Vault (where mp-host keeps hosting credentials).

Pages in this repository

  • articles/attributes — Every networked class is a partial class deriving from NetEntity (the base type lives in the adapter assembly, Unity.Multiplayer; see…
  • articles/bots — A bot is your game, launched headless with -bot <role>, playing itself over the real network. The library does all of the plumbing: it…
  • articles/case-study-cursory — Unity.Cursory is Cursory, the co-op physics puzzle, rebuilt in Unity 6 with a dedicated server and host multiplayer. Each player is a…
  • articles/ci-secrets — The Unity jobs in CI and the nightly smoke test run Unity through GameCI, which needs a Unity license on the GitHub runner. Those secrets…
  • articles/front-end — A multiplayer game needs the same screens every time: a main menu with Host and Join, somewhere to type an address or a join code, a lobby…
  • articles/getting-started — By the end of this page you have a brand-new Unity project that is a working multiplayer game. It has a main menu with Host, Join by IP…
  • articles/hosting — Every dedicated-server option in Unity.Multiplayer runs the same provider-neutral server package (UM-T23: a self-contained Linux build…
  • articles/hosting/aws-ec2 — A big-cloud profile (UM-T27): mp-host creates a VPC security group it owns, then an EC2 instance running the same Docker image +…
  • articles/hosting/aws-lightsail — The simpler of the two AWS profiles (UM-T27): one Lightsail instance running the same Docker image
  • articles/hosting/azure-vm — A big-cloud profile (UM-T27): mp-host creates the four ARM resources a Linux VM needs -- a network security group (NSG), a static public…
  • articles/hosting/digitalocean — A UM-T26 plain-VPS cloud profile: mp-host creates the droplet itself through DigitalOcean's REST API (https://api.digitalocean.com/v2)…
  • articles/hosting/edgegap — The per-match allocation profile (UM-T29): instead of one server that stays up (GenericVps, RunPod and the rest of the hosting table),…
  • articles/hosting/flyio — A UM-T28 profile: mp-host creates the app and its machine straight through Fly's Machines API (https://api.machines.dev/v1) -- no flyctl…
  • articles/hosting/gamelift — A managed-fleet profile (UM-T30), and the odd one out in this table in two ways at once: it is the only profile that is both provisioned…
  • articles/hosting/gameye — The second per-match allocation profile (UM-T29), alongside Edgegap: Gameye starts one session per match, on demand, in a location you…
  • articles/hosting/gce — A big-cloud profile (UM-T27): mp-host creates a firewall rule it owns plus a GCE instance running the same Docker image + rendezvous…
  • articles/hosting/genericvps — The default profile (UM-T23): your server package runs as a Docker container beside the rendezvous service on any UDP-capable Linux VPS…
  • articles/hosting/hetzner — A UM-T26 plain-VPS cloud profile: mp-host creates the server itself through Hetzner's REST API (https://api.hetzner.cloud/v1) from an…
  • articles/hosting/linode — A UM-T26 plain-VPS cloud profile: mp-host creates the instance itself through Linode's REST API (https://api.linode.com/v4) from an Ubuntu…
  • articles/hosting/local — The free/home option with no rented host at all (UM-T31): mp-host local up/mp-host local down run the already-built server package as a…
  • articles/hosting/oracle-oci — A UM-T31 profile: Oracle's Always Free tier gives every tenancy either an Ampere A1 (ARM64) compute allowance (up to 4 OCPUs/24 GB total,…
  • articles/hosting/ovhcloud — A UM-T26 plain-VPS cloud profile: mp-host creates a Public Cloud instance itself through OVH's REST API…
  • articles/hosting/runpod — The WebSocket-transport profile (UM-T23): your server package runs as a single RunPod pod, reachable over a RunPod-mapped TCP port. Unlike…
  • articles/hosting/vultr — A UM-T26 plain-VPS cloud profile: mp-host creates the instance itself through Vultr's REST API (https://api.vultr.com/v2) from an Ubuntu…
  • articles/join-codes — A join code is a short, typeable string that resolves to a server — ABC-DEF-GHJ — so players never type an IP address. One interface, two…
  • articles/kit — Unity.Multiplayer is one of three MindAttic packages that are built, tested and released to work as one kit. Together they are a one-stop…
  • articles/multiplayer-ready — Every MindAttic Unity game is built so that co-op or PvP can be added later without re-architecting, even when it ships single-player…
  • articles/objects — A game usually knows its objects by its own names: a level's block b12, the door door:A, the scoreboard. On a client, though, a spawned…
  • articles/players — Every multiplayer game needs to know who is playing: a name over each character, a colour for each team mate, a scoreboard, a ping column,…
  • articles/porting — A guide for moving an existing Unity game — single-player, or already networked some other way — onto Unity.Multiplayer. The order below…
  • articles/reconnect-seats — A player who drops gets the same spot back: the same seat index, the same player object, not a new one spawned from scratch. This is built…
  • articles/testing — A networked game is only as good as its tests over a real connection, so the package ships a test kit — the Unity.Multiplayer.Testing…
  • articles/topologies — The same game code runs three ways. The topology is configuration (NetConfig.Topology / Topology), never a code fork — BIBLE's product…
  • articles/troubleshooting — Errors and symptoms this package produces most, grouped by where they show up.
  • articles/votes — Most multiplayer games end up needing a vote: restart the round, skip the map, change the level, remove a griefer. The votes kit is that…
  • MindAttic.Unity.Multiplayer — Project Bible — Status legend: ✅ done (verified by a test/build) · 🟡 partial · ⬜ planned · living.
  • Unity.Multiplayer — The one-stop shop for multiplayer Unity 6 games. With its two sibling packages, MindAttic Components and Unity.Shared, it is one kit that…
  • Unity.Multiplayer — Release charter — The kit for multiplayer Unity 6 games (com.mindattic.unity.multiplayer, on Netcode for GameObjects): attribute RPCs and synced fields,…
  • rfc/0001-architecture — 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…
  • rfc/0002-generator-spike — Can a Roslyn IIncrementalGenerator turn a C# 9 extended partial method into an NGO [Rpc(SendTo.Server)] stub, and a marked field into a…
  • Unity.Multiplayer — Product specification — Place in the ecosystem: An engine kit (docs/ECOSYSTEM.md §2.1): the netcode every MindAttic Unity game uses.
From Unity.Multiplayer/docs/overview.md via MindAttic.Docs; synced automatically, so edit the repo, not this page.