uw-network-setup
Skill44 starsChanged 8 months agoMITView on GitHub
Generates networking boilerplate adapted to the project's chosen networking package (NGO, Mirror, Photon). Use when setting up multiplayer systems, syncing state, writing RPCs, building lobbies, or designing an authority matrix. Triggers on requests like "add multiplayer", "sync player health", "create an RPC", "set up lobbies", "make this networked", "add co-op", "replicate this across clients", "spawn networked objects", "handle player disconnect", "create a matchmaking system", or any task involving network state synchronization, remote procedure calls, or client-server architecture. Always reads ProjectConfig.yaml -> networking before generating code. If networking is "none", do NOT generate networking code.
In this repository13 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- uw-code-reviewSkill
- uw-dependency-injectionSkill
- uw-game-feel-integratorSkill
- uw-scriptable-object-archSkill
- uw-skill-creatorSkill
- uw-state-machineSkill
- uw-ui-toolkit-binderSkill
- uw-unity-debuggingSkill
- uw-unity-editor-toolsSkill
- uw-unity-feature-scaffoldSkill
- uw-unity-project-setupSkill
- uw-unity-test-runnerSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
13 rules. About 0 are common, 2 are distinctive, and 11 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
11
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 16
Read docs/TDD_Template.md for the authority matrix (who owns what data).
- Very specific: line 17
Read docs/CODING_STANDARDS.md for async patterns (Awaitable + CancellationToken) and class structure.
- Very specific: line 18
Read docs/NAMING_CONVENTIONS.md for file/class naming.
- Distinctive: line 32
Every package has a mechanism for syncing state from server/host to clients.
- Very specific: line 133
When the project might switch networking packages later, or when using DI (architecture_pattern: "di-first"), wrap networking behind an …
- Distinctive: line 150
When syncing custom structs over the network, each package has its own serialization approach:
- Very specific: line 183
DI integration: If architecture_pattern: "di-first", use uw-dependency-injection to register network services in the container.
- Very specific: line 184
Write tests: Use uw-unity-test-runner — test game logic in EditMode by mocking INetworkService.
- Very specific: line 192
Use [SerializeField] private for prefab references and configuration — never public fields.
- Very specific: line 193
Check the package version in ProjectConfig.yaml before using any API — breaking changes happen between major versions.
- Very specific: line 194
Use Awaitable with CancellationToken for async network operations (connection, scene loading) per CODING_STANDARDS.md.
- Very specific: line 195
All networking code must live inside an .asmdef.
- Very specific: line 196
If ProjectConfig.yaml -> mcp.unity_mcp is true, call refresh_unity after creating files.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Network Setup
Generate networking code adapted to the project's chosen package.
Before You Start
- Read
docs/ProjectConfig.yamlfor:networking— the package name ("ngo","mirror","photon", or"none"). If"none", stop — do not generate networking code.architecture_pattern—"so-first"or"di-first"(affects how network services are wired).mcp.unity_mcp— iftrue, callrefresh_unityafter creating files.
- Read
docs/TDD_Template.mdfor the authority matrix (who owns what data). - Read
docs/CODING_STANDARDS.mdfor async patterns (Awaitable+CancellationToken) and class structure. - Read
docs/NAMING_CONVENTIONS.mdfor file/class naming.
Package Quick Reference
Each package has a detailed reference file. Read the relevant one before generating code:
- NGO (Netcode for GameObjects): references/ngo.md — Unity's first-party solution. Uses
NetworkVariable,[Rpc]attributes. - Mirror: references/mirror.md — Community open-source. Uses
[SyncVar],[Command]/[ClientRpc]. - Photon (PUN2/Fusion): references/photon.md — Cloud-hosted. Uses
IPunObservable,[PunRPC].
Core Patterns (All Packages)
State Synchronization
Every package has a mechanism for syncing state from server/host to clients. The pattern is the same — only the syntax differs.
| Package | Sync Mechanism | Change Callback | Example |
| NGO | NetworkVariable<T> | .OnValueChanged += handler | _health.OnValueChanged += OnHealthChanged; |
| Mirror | [SyncVar(hook = nameof(...))] | Hook method | [SyncVar(hook = nameof(OnHealthChanged))] |
| Photon | IPunObservable | OnPhotonSerializeView | Manual read/write in serialize callback |
Remote Procedure Calls (RPCs)
RPCs let clients request actions on the server, or the server push updates to clients.
NGO:
[Rpc(SendTo.Server)]
public void RequestDamageServerRpc(int amount)
{
// Runs on server — validate before applying
if (amount < 0 || amount > MAX_DAMAGE) return;
_health.Value = Mathf.Max(0, _health.Value - amount);
}
[Rpc(SendTo.ClientsAndHost)]
public void PlayHitEffectClientRpc()
{
// Runs on all clients — visual/audio only, no game state
}Mirror:
[Command]
public void CmdRequestDamage(int amount)
{
if (amount < 0 || amount > MAX_DAMAGE) return;
_health = Mathf.Max(0, _health - amount);
RpcPlayHitEffect();
}
[ClientRpc]
public void RpcPlayHitEffect()
{
// Visual/audio feedback on all clients
}Photon:
public void RequestDamage(int amount)
{
photonView.RPC(nameof(RpcTakeDamage), RpcTarget.MasterClient, amount);
}
[PunRPC]
private void RpcTakeDamage(int amount, PhotonMessageInfo info)
{
if (!PhotonNetwork.IsMasterClient) return;
if (amount < 0 || amount > MAX_DAMAGE) return;
_health = Mathf.Max(0, _health - amount);
}Network Object Spawning
Spawning networked objects follows the same principle: only the server/host creates the authoritative instance, and the network layer replicates it to clients.
NGO:
// Server only — spawn a networked prefab
var instance = Instantiate(_projectilePrefab, spawnPoint.position, spawnPoint.rotation);
instance.GetComponent<NetworkObject>().Spawn();Mirror:
// Server only
var instance = Instantiate(_projectilePrefab, spawnPoint.position, spawnPoint.rotation);
NetworkServer.Spawn(instance);Photon:
// Room owner or any client (Photon handles ownership)
PhotonNetwork.Instantiate(_projectilePrefabName, spawnPoint.position, spawnPoint.rotation);Authority Matrix Template
Define who owns, reads, and writes each piece of networked state. Fill this in before writing code — it prevents authority bugs.
| Entity | Owner | Read | Write | Sync Method | Validation |
| Player Health | Server | Everyone | Server | NetworkVariable / SyncVar | Clamp 0-max, rate limit |
| Player Position | Server | Everyone | Server | NetworkTransform | Speed cap, teleport check |
| Player Input | Client | Server | Owner | RPC (client -> server) | Sanitize on server |
| Chat Messages | Client | Everyone | Owner | RPC | Length limit, rate limit |
| Game Timer | Server | Everyone | Server | NetworkVariable / SyncVar | Server-authoritative only |
| Inventory | Server | Owner | Server | RPC + NetworkVariable | Validate item exists |
Abstraction Layer (Optional)
When the project might switch networking packages later, or when using DI (architecture_pattern: "di-first"), wrap networking behind an interface:
public interface INetworkService
{
bool IsServer { get; }
bool IsClient { get; }
bool IsConnected { get; }
void SendToServer<T>(T message) where T : struct;
void SendToClients<T>(T message) where T : struct;
}Register the concrete implementation in the DI container (see uw-dependency-injection). Game systems depend on INetworkService, not the package directly. This makes testing easier too — mock the interface in EditMode tests.
Custom Type Serialization
When syncing custom structs over the network, each package has its own serialization approach:
NGO — implement INetworkSerializable:
public struct DamageEvent : INetworkSerializable
{
public int Amount;
public ulong AttackerId;
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
{
serializer.SerializeValue(ref Amount);
serializer.SerializeValue(ref AttackerId);
}
}Mirror — implement custom Reader/Writer extensions or use [SyncVar] with supported types.
Photon — serialize manually in OnPhotonSerializeView or register custom types with PhotonPeer.RegisterType.
Client Prediction & Lag Compensation
For responsive gameplay (especially movement and shooting), client-side prediction avoids waiting for server confirmation:
- Client predicts — apply input locally immediately.
- Server validates — process the input authoritatively, send correction.
- Client reconciles — if server state differs from prediction, snap or interpolate to correct position.
This is complex. NGO has built-in NetworkTransform prediction. Mirror has community prediction examples. Photon Fusion has built-in state authority with rollback. For custom prediction, start with movement only and expand from there.
After Setup
- DI integration: If
architecture_pattern: "di-first", useuw-dependency-injectionto register network services in the container. - Write tests: Use
uw-unity-test-runner— test game logic in EditMode by mockingINetworkService. Test actual networking in PlayMode. - Authority matrix: Fill in
docs/TDD_Template.mdwith the authority matrix before writing any sync code.
Rules
- Server-authoritative unless
docs/TDD_Template.mdexplicitly specifies peer-to-peer. - Never trust client input — always validate on the server (bounds check, rate limit, permission check).
- Cache
NetworkBehaviourreferences inAwake()orOnNetworkSpawn()— neverGetComponentinUpdate. - Use
[SerializeField] privatefor prefab references and configuration — never public fields. - Check the package version in
ProjectConfig.yamlbefore using any API — breaking changes happen between major versions. - Use
AwaitablewithCancellationTokenfor async network operations (connection, scene loading) perCODING_STANDARDS.md. - All networking code must live inside an
.asmdef. - If
ProjectConfig.yaml -> mcp.unity_mcpistrue, callrefresh_unityafter creating files.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

