[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M792M37WRKRHJWVGX7TRSTR4":3,"skill-same:01M792M37WRKRHJWVGX7TRSTR4":62},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":26,"commitSha":27,"skillDirectory":28,"forksCount":29,"repositoryHtmlUrl":30,"repositoryHomepageUrl":31,"ownerHtmlUrl":32,"ownerBlogUrl":33,"ownerDescription":34,"updatedAt":35,"install":36,"resources":49},"01M792M37WRKRHJWVGX7TRSTR4","unity-multiplayer",null,"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.","poorvith-mp\u002Fskills-gamedev","poorvith-mp","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F277478855?v=4","01M78Z5K0YH1Z3PX815PGQ96ND","Poorvith M P","01M792GVN0NZ9V49H6Q6BE3S1S",5,"MIT","https:\u002F\u002Fgithub.com\u002Fpoorvith-mp\u002Fskills-gamedev\u002Fblob\u002Fmain\u002Fskills\u002Funity-multiplayer\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: unity-multiplayer\nlast_reviewed: 2026-09-06\ngroup: Unity\ndescription: 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.\n---\n\n# unity-multiplayer\n\n## Core Philosophy\nMultiplayer 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.\n\n---\n\n## 4-Step Unity Multiplayer Architecture\n\n### Step 1: Topology & Transport (NGO + Relay + Lobby)\n1. **Network Topology**:\n   - **Dedicated Game Server (DGS)**: Absolute authority, zero host advantage, highest server cost. Best for competitive matchmaking.\n   - **Listen Server \u002F Host-Client**: One player acts as both host and server. Zero server cost, but host has 0ms latency advantage.\n2. **Unity Transport & Relay**:\n   - 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.\n3. **Unity Lobby**:\n   - Handles room matchmaking, player slot reservations, and custom lobby metadata before spinning up the network transport.\n\n### Step 2: Server Authority & NetworkVariables\n1. **`NetworkBehaviour` & Ownership**:\n   - Code checks `IsServer`, `IsClient`, and `IsOwner`:\n     ```csharp\n     if (!IsOwner) return; \u002F\u002F Only local player handles input\n     ```\n2. **`NetworkVariable\u003CT>`**:\n   - Replicates state from Server $\\to$ Clients automatically:\n     ```csharp\n     public NetworkVariable\u003Cint> Health = new(\n         100, \n         NetworkVariableReadPermission.Everyone, \n         NetworkVariableWritePermission.Server \u002F\u002F Never allow client writes!\n     );\n     ```\n\n### Step 3: Remote Procedure Calls (RPCs)\n1. **ServerRpc**: Client calls, Server executes (e.g. *RequestFireWeaponServerRpc*).\n2. **ClientRpc**: Server calls, all Clients execute (e.g. *PlayExplosionFxClientRpc*).\n3. **RPC Rule of Thumb**:\n   - Use `NetworkVariable` for persistent state (Health, Gold, Position).\n   - Use `RPCs` for transient one-off events (Sound effects, particle spawns).\n\n### Step 4: Lag Compensation & Client Prediction\n1. **Client-Side Prediction**:\n   - Client immediately applies local input and updates position locally without waiting for server confirmation round-trip.\n2. **Server Reconciliation**:\n   - Server validates movement:\n     $$\\Delta \\vec{p} \\le \\vec{v}_{\\text{max}} \\times \\Delta t + \\epsilon$$\n   - If client position drifts beyond error threshold $\\epsilon$, server overwrites client position with authoritative coordinates, and client smoothly blends to the corrected position.\n3. **Lag Compensated Hitbox History**:\n   - Server rewinds player hitboxes back in time by the attacker's latency $T_{\\text{rtt}} \u002F 2$ to verify if the shot lined up when the client pulled the trigger.\n\n---\n\n## Deliverable Format: Server-Authoritative NGO Weapon Firing Pattern\n\n```csharp\nusing Unity.Netcode;\nusing UnityEngine;\n\npublic class NetworkPlayerWeapon : NetworkBehaviour {\n    [SerializeField] private GameObject bulletPrefab;\n    [SerializeField] private Transform muzzleTransform;\n\n    private void Update() {\n        if (!IsOwner) return;\n        if (Input.GetButtonDown(\"Fire1\")) {\n            \u002F\u002F Request firing to the authoritative server\n            FireWeaponServerRpc(muzzleTransform.position, muzzleTransform.forward);\n        }\n    }\n\n    [ServerRpc]\n    private void FireWeaponServerRpc(Vector3 origin, Vector3 direction) {\n        \u002F\u002F Server validation check\n        if (Vector3.Distance(origin, muzzleTransform.position) > 1.5f) {\n            Debug.LogWarning($\"[Security] Player {OwnerClientId} origin spoofing detected!\");\n            return;\n        }\n\n        \u002F\u002F Spawn networked bullet\n        GameObject bullet = Instantiate(bulletPrefab, origin, Quaternion.LookRotation(direction));\n        bullet.GetComponent\u003CNetworkObject>().Spawn();\n        \n        \u002F\u002F Notify all clients to play audio\u002Fvfx\n        PlayMuzzleFlashClientRpc();\n    }\n\n    [ClientRpc]\n    private void PlayMuzzleFlashClientRpc() {\n        \u002F\u002F Play local visual muzzle flash and sound effect\n    }\n}\n```\n\n---\n\n## Worked Example: Resolving Rubberbanding in a Fast-Paced Arena Shooter\n\n- **Problem**: In an action arena shooter built on NGO, players with 120ms ping experienced jarring stutter and teleportation (rubberbanding) whenever sprinting.\n- **Root Cause**: The server was transmitting absolute position snapshots at 20Hz; client prediction was lacking, snapping the local player to historical server coordinates.\n- **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.\n- **Result**: Movement became completely smooth for players with up to 180ms latency.\n\n---\n\n## Verification Checklist\n\n- [ ] All `NetworkVariable` write permissions set strictly to `Server`.\n- [ ] Unity Relay service handles NAT punchthrough without manual port forwarding.\n- [ ] Client movement inputs validated server-side against maximum acceleration limits.\n- [ ] Weapon hit registration verified on server using historical hitbox rewind.\n- [ ] Network objects cleanly despawned using `NetworkObject.Despawn()` on disconnect.\n\n---\n\n## Anti-Patterns\n\n- **Client-Authoritative Damage**: Allowing clients to send `DealDamageServerRpc(targetId, 9999)` without server-side weapon range, line-of-sight, or ammo validation.\n- **Over-Broadcasting RPCs Every Frame**: Sending continuous transform updates via RPCs instead of compressed `NetworkTransform` ticks.\n- **Ignoring Network Disconnections**: Leaving orphaned player GameObjects in the scene when a client forcibly disconnects or loses connection.\n","# unity-multiplayer\n\n## Core Philosophy\nMultiplayer 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.\n\n---\n\n## 4-Step Unity Multiplayer Architecture\n\n### Step 1: Topology & Transport (NGO + Relay + Lobby)\n1. **Network Topology**:\n   - **Dedicated Game Server (DGS)**: Absolute authority, zero host advantage, highest server cost. Best for competitive matchmaking.\n   - **Listen Server \u002F Host-Client**: One player acts as both host and server. Zero server cost, but host has 0ms latency advantage.\n2. **Unity Transport & Relay**:\n   - 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.\n3. **Unity Lobby**:\n   - Handles room matchmaking, player slot reservations, and custom lobby metadata before spinning up the network transport.\n\n### Step 2: Server Authority & NetworkVariables\n1. **`NetworkBehaviour` & Ownership**:\n   - Code checks `IsServer`, `IsClient`, and `IsOwner`:\n     ```csharp\n     if (!IsOwner) return; \u002F\u002F Only local player handles input\n     ```\n2. **`NetworkVariable\u003CT>`**:\n   - Replicates state from Server $\\to$ Clients automatically:\n     ```csharp\n     public NetworkVariable\u003Cint> Health = new(\n         100, \n         NetworkVariableReadPermission.Everyone, \n         NetworkVariableWritePermission.Server \u002F\u002F Never allow client writes!\n     );\n     ```\n\n### Step 3: Remote Procedure Calls (RPCs)\n1. **ServerRpc**: Client calls, Server executes (e.g. *RequestFireWeaponServerRpc*).\n2. **ClientRpc**: Server calls, all Clients execute (e.g. *PlayExplosionFxClientRpc*).\n3. **RPC Rule of Thumb**:\n   - Use `NetworkVariable` for persistent state (Health, Gold, Position).\n   - Use `RPCs` for transient one-off events (Sound effects, particle spawns).\n\n### Step 4: Lag Compensation & Client Prediction\n1. **Client-Side Prediction**:\n   - Client immediately applies local input and updates position locally without waiting for server confirmation round-trip.\n2. **Server Reconciliation**:\n   - Server validates movement:\n     $$\\Delta \\vec{p} \\le \\vec{v}_{\\text{max}} \\times \\Delta t + \\epsilon$$\n   - If client position drifts beyond error threshold $\\epsilon$, server overwrites client position with authoritative coordinates, and client smoothly blends to the corrected position.\n3. **Lag Compensated Hitbox History**:\n   - Server rewinds player hitboxes back in time by the attacker's latency $T_{\\text{rtt}} \u002F 2$ to verify if the shot lined up when the client pulled the trigger.\n\n---\n\n## Deliverable Format: Server-Authoritative NGO Weapon Firing Pattern\n\n```csharp\nusing Unity.Netcode;\nusing UnityEngine;\n\npublic class NetworkPlayerWeapon : NetworkBehaviour {\n    [SerializeField] private GameObject bulletPrefab;\n    [SerializeField] private Transform muzzleTransform;\n\n    private void Update() {\n        if (!IsOwner) return;\n        if (Input.GetButtonDown(\"Fire1\")) {\n            \u002F\u002F Request firing to the authoritative server\n            FireWeaponServerRpc(muzzleTransform.position, muzzleTransform.forward);\n        }\n    }\n\n    [ServerRpc]\n    private void FireWeaponServerRpc(Vector3 origin, Vector3 direction) {\n        \u002F\u002F Server validation check\n        if (Vector3.Distance(origin, muzzleTransform.position) > 1.5f) {\n            Debug.LogWarning($\"[Security] Player {OwnerClientId} origin spoofing detected!\");\n            return;\n        }\n\n        \u002F\u002F Spawn networked bullet\n        GameObject bullet = Instantiate(bulletPrefab, origin, Quaternion.LookRotation(direction));\n        bullet.GetComponent\u003CNetworkObject>().Spawn();\n        \n        \u002F\u002F Notify all clients to play audio\u002Fvfx\n        PlayMuzzleFlashClientRpc();\n    }\n\n    [ClientRpc]\n    private void PlayMuzzleFlashClientRpc() {\n        \u002F\u002F Play local visual muzzle flash and sound effect\n    }\n}\n```\n\n---\n\n## Worked Example: Resolving Rubberbanding in a Fast-Paced Arena Shooter\n\n- **Problem**: In an action arena shooter built on NGO, players with 120ms ping experienced jarring stutter and teleportation (rubberbanding) whenever sprinting.\n- **Root Cause**: The server was transmitting absolute position snapshots at 20Hz; client prediction was lacking, snapping the local player to historical server coordinates.\n- **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.\n- **Result**: Movement became completely smooth for players with up to 180ms latency.\n\n---\n\n## Verification Checklist\n\n- [ ] All `NetworkVariable` write permissions set strictly to `Server`.\n- [ ] Unity Relay service handles NAT punchthrough without manual port forwarding.\n- [ ] Client movement inputs validated server-side against maximum acceleration limits.\n- [ ] Weapon hit registration verified on server using historical hitbox rewind.\n- [ ] Network objects cleanly despawned using `NetworkObject.Despawn()` on disconnect.\n\n---\n\n## Anti-Patterns\n\n- **Client-Authoritative Damage**: Allowing clients to send `DealDamageServerRpc(targetId, 9999)` without server-side weapon range, line-of-sight, or ammo validation.\n- **Over-Broadcasting RPCs Every Frame**: Sending continuous transform updates via RPCs instead of compressed `NetworkTransform` ticks.\n- **Ignoring Network Disconnections**: Leaving orphaned player GameObjects in the scene when a client forcibly disconnects or loses connection.\n",{"name":5,"group":24,"description":7,"last_reviewed":25},"Unity",1788652800000,"main","d661d370a67c4532034e3d1d87c4aec237077f34","skills\u002Funity-multiplayer",0,"https:\u002F\u002Fgithub.com\u002Fpoorvith-mp\u002Fskills-gamedev","https:\u002F\u002Fgithub.com\u002Fpoorvith-mp\u002Fskillary","https:\u002F\u002Fgithub.com\u002Fpoorvith-mp","poorvithmp.com","Shipping tools for problems people notice too late.","2026-10-02 21:32:36",{"source":8,"skillName":5,"commands":37,"prompt":47,"zipAvailable":48},[38,41,44],{"tool":39,"command":40},"npx","npx skills add poorvith-mp\u002Fskills-gamedev --skill unity-multiplayer",{"tool":42,"command":43},"bunx","bunx skills add poorvith-mp\u002Fskills-gamedev --skill unity-multiplayer",{"tool":45,"command":46},"pnpm","pnpm dlx skills add poorvith-mp\u002Fskills-gamedev --skill unity-multiplayer","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fpoorvith-mp\u002Fskills-gamedev\u002Fblob\u002Fmain\u002Fskills\u002Funity-multiplayer\u002FSKILL.md",true,[50,56],{"path":51,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":54,"sourceHtmlUrl":55},"evals\u002Frouting.yaml","REFERENCE","参考文档",959,"https:\u002F\u002Fgithub.com\u002Fpoorvith-mp\u002Fskills-gamedev\u002Fblob\u002Fmain\u002Fskills\u002Funity-multiplayer\u002Fevals\u002Frouting.yaml",{"path":57,"resourceType":58,"resourceTypeDesc":59,"sizeBytes":60,"sourceHtmlUrl":61},"unity-multiplayer.skill","OTHER","其他",3584,"https:\u002F\u002Fgithub.com\u002Fpoorvith-mp\u002Fskills-gamedev\u002Fblob\u002Fmain\u002Fskills\u002Funity-multiplayer\u002Funity-multiplayer.skill",[63,70,77,84,91,98],{"skillNo":64,"name":65,"nameZh":6,"description":66,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":67,"categories":68,"keywords":69,"publishedAt":19},"01M792N6JWJ1J9XBK6HKFHWRHA","unreal-worlds","Build open worlds with World Partition, Landscape, procedural foliage, HLOD and level streaming. Use when sculpting landscapes, biomes, or World Partition in Unreal.","https:\u002F\u002Fgithub.com\u002Fpoorvith-mp\u002Fskills-gamedev\u002Fblob\u002Fmain\u002Fskills\u002Funreal-worlds\u002FSKILL.md",[],[],{"skillNo":71,"name":72,"nameZh":6,"description":73,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":74,"categories":75,"keywords":76,"publishedAt":19},"01M792N3JHMS0FWY4YJJ4X60PV","unreal-world-builder","Moved to unreal-worlds in skills-gamedev. Removed in v4.1.","https:\u002F\u002Fgithub.com\u002Fpoorvith-mp\u002Fskills-gamedev\u002Fblob\u002Fmain\u002Fskills\u002Funreal-world-builder\u002FSKILL.md",[],[],{"skillNo":78,"name":79,"nameZh":6,"description":80,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":81,"categories":82,"keywords":83,"publishedAt":19},"01M792N0XGH0E9XK3ZCR34Z18B","unreal-technical-artist","Moved to unreal-tech-art in skills-gamedev. Removed in v4.1.","https:\u002F\u002Fgithub.com\u002Fpoorvith-mp\u002Fskills-gamedev\u002Fblob\u002Fmain\u002Fskills\u002Funreal-technical-artist\u002FSKILL.md",[],[],{"skillNo":85,"name":86,"nameZh":6,"description":87,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":19},"01M792MXKCZ26XGP5RDQHDWRWS","unreal-tech-art","Own the UE5 visual pipeline: Material Editor, Niagara VFX and Procedural Content Generation. Use when creating Unreal materials, Niagara visual effects, or Lumen setups.","https:\u002F\u002Fgithub.com\u002Fpoorvith-mp\u002Fskills-gamedev\u002Fblob\u002Fmain\u002Fskills\u002Funreal-tech-art\u002FSKILL.md",[],[],{"skillNo":92,"name":93,"nameZh":6,"description":94,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":95,"categories":96,"keywords":97,"publishedAt":19},"01M792MRZ9PB1MNFKPNVDB5AJP","unreal-systems","Work the C++\u002FBlueprint continuum with Nanite, Lumen and the Gameplay Ability System. Use when developing Unreal Engine gameplay in C++, Blueprints, or GAS.","https:\u002F\u002Fgithub.com\u002Fpoorvith-mp\u002Fskills-gamedev\u002Fblob\u002Fmain\u002Fskills\u002Funreal-systems\u002FSKILL.md",[],[],{"skillNo":99,"name":100,"nameZh":6,"description":101,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":102,"categories":103,"keywords":104,"publishedAt":19},"01M792MQGJ5S2EFDAD5BN5B8V3","unreal-systems-engineer","Moved to modernized catalog in skillary. Removed in v4.1.","https:\u002F\u002Fgithub.com\u002Fpoorvith-mp\u002Fskills-gamedev\u002Fblob\u002Fmain\u002Fskills\u002Funreal-systems-engineer\u002FSKILL.md",[],[]]