poorvith-mp/skills-gamedev/unity-multiplayer
Claude Code and agent skill by poorvith-mp/skills-gamedev
- community
Checking that the SKILL.md file is still in the repository.
Build Netcode for GameObjects, Relay and Lobby, server authority and lag compensation. For exploit defense, see anti-cheat. Use when implementing Netcode for GameObjects or sync.
Install
npx vskill@latest install poorvith-mp/skills-gamedev/unity-multiplayerSKILL.md
unity-multiplayer
Core Philosophy
Multiplayer game programming is an exercise in distributed systems operating under the constraints of physics and latency. You cannot trust the client; anything calculated on a player's machine—hit detection, movement speed, inventory transactions—will inevitably be hacked. High-performance Unity multiplayer requires a server-authoritative model with Netcode for GameObjects (NGO), Unity Relay & Lobby for NAT traversal, and client-side prediction with server reconciliation to mask network latency for players.
4-Step Unity Multiplayer Architecture
Step 1: Topology & Transport (NGO + Relay + Lobby)
- Network Topology:
- Dedicated Game Server (DGS): Absolute authority, zero host advantage, highest server cost. Best for competitive matchmaking.
- Listen Server / Host-Client: One player acts as both host and server. Zero server cost, but host has 0ms latency advantage.
- Unity Transport & Relay:
- Use Unity Transport Package (UTP) combined with Unity Relay service to pierce corporate firewalls and symmetric NATs without requiring players to configure router port forwarding.
- Unity Lobby:
- Handles room matchmaking, player slot reservations, and custom lobby metadata before spinning up the network transport.
Step 2: Server Authority & NetworkVariables
- `NetworkBehaviour` & Ownership:
- Code checks
IsServer,IsClient, andIsOwner:
``csharp if (!IsOwner) return; // Only local player handles input ``
- `NetworkVariable<T>`:
- Replicates state from Server $\to$ Clients automatically:
``csharp public NetworkVariable<int> Health = new( 100, NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Server // Never allow client writes! ); ``
Step 3: Remote Procedure Calls (RPCs)
- ServerRpc: Client calls, Server executes (e.g. RequestFireWeaponServerRpc).
- ClientRpc: Server calls, all Clients execute (e.g. PlayExplosionFxClientRpc).
- RPC Rule of Thumb:
- Use
NetworkVariablefor persistent state (Health, Gold, Position). - Use
RPCsfor transient one-off events (Sound effects, particle spawns).
Step 4: Lag Compensation & Client Prediction
- Client-Side Prediction:
- Client immediately applies local input and updates position locally without waiting for server confirmation round-trip.
- Server Reconciliation:
- Server validates movement:
$$\Delta \vec{p} \le \vec{v}_{\text{max}} \times \Delta t + \epsilon$$
- If client position drifts beyond error threshold $\epsilon$, server overwrites client position with authoritative coordinates, and client smoothly blends to the corrected position.
- Lag Compensated Hitbox History:
- Server rewinds player hitboxes back in time by the attacker's latency $T_{\text{rtt}} / 2$ to verify if the shot lined up when the client pulled the trigger.
Deliverable Format: Server-Authoritative NGO Weapon Firing Pattern
Worked Example: Resolving Rubberbanding in a Fast-Paced Arena Shooter
- Problem: In an action arena shooter built on NGO, players with 120ms ping experienced jarring stutter and teleportation (rubberbanding) whenever sprinting.
- Root Cause: The server was transmitting absolute position snapshots at 20Hz; client prediction was lacking, snapping the local player to historical server coordinates.
- Solution: Implemented tick-based input buffering and reconciliation. Client stores a history buffer of unconfirmed input ticks. When receiving a server correction, the client re-simulates all unacknowledged ticks from the corrected state.
- Result: Movement became completely smooth for players with up to 180ms latency.
Verification Checklist
- [ ] All
NetworkVariablewrite permissions set strictly toServer. - [ ] Unity Relay service handles NAT punchthrough without manual port forwarding.
- [ ] Client movement inputs validated server-side against maximum acceleration limits.
- [ ] Weapon hit registration verified on server using historical hitbox rewind.
- [ ] Network objects cleanly despawned using
NetworkObject.Despawn()on disconnect.
Anti-Patterns
- Client-Authoritative Damage: Allowing clients to send
DealDamageServerRpc(targetId, 9999)without server-side weapon range, line-of-sight, or ammo validation. - Over-Broadcasting RPCs Every Frame: Sending continuous transform updates via RPCs instead of compressed
NetworkTransformticks. - Ignoring Network Disconnections: Leaving orphaned player GameObjects in the scene when a client forcibly disconnects or loses connection.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/unity-multiplayer/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/poorvith-mp/skills-gamedev/unity-multiplayer)