unity-netcode-design

Provides source-anchored design rules for Netcode for GameObjects 2.x multiplayer code.

Updated Jun 21, 2026
One-click install
npx skills add https://github.com/du-qwq/Shader-Writing-Architecture-and-Specifications --skill unity-netcode-design-du-qwq
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: unity-netcode-design
Source: https://github.com/du-qwq/Shader-Writing-Architecture-and-Specifications/tree/main/.agents/skills/unity-skills/skills/netcode-design
Command: npx skills add https://github.com/du-qwq/Shader-Writing-Architecture-and-Specifications --skill unity-netcode-design-du-qwq

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing Unity multiplayer code with Netcode for GameObjects often leads to subtle bugs: RPCs that never fire, NetworkVariables that fail to sync, ownership checks evaluated at the wrong lifecycle stage, and hallucinated APIs that do not exist. This Skill supplies design rules distilled directly from the Netcode for GameObjects 2.x source code, each with a file/line citation, so generated or reviewed netcode follows the framework's actual behavior. ## Core Features & Use Cases - Lifecycle and ownership rules: Documents the exact Awake/OnNetworkSpawn/Start ordering, the IsServer/IsClient/IsOwner permission matrix, and ownership transfer semantics including Distributed Authority mode. - RPC and NetworkVariable guidance: Covers the universal [Rpc(SendTo.X)] model, legacy ServerRpc/ClientRpc naming constraints, parameter serialization limits, and NetworkVariable/NetworkList type constraints. - Spawning, scenes, and transport: Explains prefab registration, Spawn/Despawn authority, NetworkSceneManager server-driven scene loading, and UnityTransport direct-connect versus Relay configuration. - Pitfalls checklist: A 30-item catalog of the bugs AI agents most often introduce, each with a source anchor and a corrected pattern. - Use Case: When asked to write a NetworkBehaviour that syncs player health, load this Skill to produce code that initializes the NetworkVariable at field declaration, seeds values in OnNetworkSpawn, unsubscribes in OnNetworkDespawn, and routes client writes through a ServerRpc. ## Quick Start Ask the assistant to review or write a Unity Netcode NetworkBehaviour script, for example to create a server-authoritative health system with an RPC-driven damage flow.

Frequently Asked Questions about unity-netcode-design

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a NetworkBehaviour with Netcode for GameObjects?

Declare NetworkVariable fields with initializers at declaration time, then override OnNetworkSpawn to subscribe to events and seed initial values on the server. Mirror every subscription with an unsubscribe in OnNetworkDespawn, and guard per-frame logic with IsSpawned.

What is the difference between [Rpc(SendTo.Server)] and [ServerRpc]?

[Rpc(SendTo.Server)] is the universal 2.x attribute with no method-name constraint, while legacy [ServerRpc] requires the method name to end with ServerRpc or ILPP fails at compile time. Both route the call to the server; the universal form is recommended.

Why is my NetworkVariable not syncing to clients?

Common causes are constructing the NetworkVariable inside OnNetworkSpawn instead of at field declaration, using an unsupported type like string or List<T>, or writing from a client when write permission defaults to Server. Use FixedString types, NetworkList, and server-side writes or Owner write permission.

Can a client call NetworkObject Spawn in Netcode for GameObjects?

No, Spawn, Despawn, and ChangeOwnership are Server/Host-only operations; client calls throw or are dropped. The client must send an RPC to the server, which then instantiates the prefab and calls Spawn.

Does Netcode for GameObjects 2.x support distributed authority?

Yes, setting NetworkConfig.NetworkTopology to DistributedAuthority removes the dedicated server role and gives each NetworkObject its own authority. Use SendTo.Authority instead of SendTo.Server, and owners may write NetworkVariables on objects they own.

Why does OnNetworkSpawn run before Start in Unity netcode?

Netcode invokes OnNetworkSpawn after Awake and OnEnable but before the first frame's Start, so network state like IsOwner and IsSpawned is valid there. Initialization depending on network state belongs in OnNetworkSpawn, not Awake or Start.