Skip to content

zwinz/unity-netcode-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unity Netcode Demo

A small, deliberately-readable multiplayer sample built with Unity 6 (6000.4) and Netcode for GameObjects (NGO) 2.x. It demonstrates a server-authoritative architecture: the server is the single source of truth, clients send intent rather than state, and no client can move itself or spawn objects directly.

Built as a focused reference for how I structure networked gameplay — clean assembly boundaries, one place that owns connection flow, and server-authoritative movement and spawning that a client can't cheat.

What it demonstrates

  • Server-authoritative movement — the owning client samples input and sends it to the server via RPC; the server simulates and a NetworkTransform replicates the result.
  • Server-authoritative spawning — players are spawned by the server on connect; a generic spawner lets clients request objects (e.g. monster waves) while the server decides whether to honour the request.
  • Centralised connection flow — a single ConnectionManager wraps NetworkManager (host / client / server, connection approval) so UI and tests never touch it directly.
  • Replicated game state — a NetworkVariable-driven state machine (Lobby → InGame → GameOver), server-writable only.
  • Custom URP shaders (hand-written HLSL) — purpose-built for the demo rather than a generic collection:
    • PlayerHighlight — fresnel rim glow to distinguish the locally-owned player.
    • HitFlash — flash-to-colour hit feedback, driven from script via a MaterialPropertyBlock (no per-instance material, stays batchable).
    • Dissolve — noise dissolve with an emissive edge for spawn / despawn.

Architecture

Owning Client                    Server (authority)                 Other Clients
─────────────                    ──────────────────                 ─────────────
sample input ──SubmitInputRpc──▶ validate + simulate movement
                                 write NetworkTransform ──replicate──▶ receive state
request spawn ─RequestSpawnRpc─▶ validate + Spawn() ────replicate──▶ receive object
                                 GameState NetworkVariable ─replicate─▶ react to state

Project layout

Assets/_Project/
  Scripts/
    Runtime/                     (asmdef: Netcode.Demo.Runtime)
      Core/                      GameBootstrap, GameState, GameStateController
      Networking/                ConnectionManager, DevConnectionUI
      Gameplay/
        Player/                  PlayerController (server-authoritative movement)
        Spawning/                PlayerSpawner, NetworkObjectSpawner
        Effects/                 HitFlashEffect (drives the HitFlash shader)
    Editor/                      (asmdef: Netcode.Demo.Editor) — tooling
    Tests/                       (asmdef: Netcode.Demo.Tests) — edit-mode + future NGO integration tests
  Art/
    Shaders/                     PlayerHighlight, HitFlash, Dissolve (URP HLSL)
  Scenes/                        Bootstrap scene (create in-editor — see Setup)
  Prefabs/                       Player / spawnable network prefabs (create in-editor)

Code is split into its own assemblies rather than living in Assembly-CSharp, so compile times stay low and dependencies are explicit.

Requirements

  • Unity 6000.4.9f1 (or a matching Unity 6 release)
  • Netcode for GameObjects 2.2.0 (already listed in Packages/manifest.json)
  • Recommended: Multiplayer Play Mode and Multiplayer Tools (network profiler), installable from the Package Manager / Multiplayer Center window.

Setup

  1. Open the project in Unity 6. On first open the Package Manager resolves NGO automatically.
  2. Create a Bootstrap scene with a single GameObject that has:
    • NetworkManager (assign a transport — Unity Transport is added with NGO)
    • ConnectionManager + DevConnectionUI
    • PlayerSpawner (assign the player prefab and spawn points)
  3. Create a Player prefab: NetworkObject + NetworkTransform (server-authoritative)
    • CharacterController + PlayerController. Register it in the NetworkManager network prefabs list.
  4. Enter Play Mode and press Host, or use Multiplayer Play Mode to run a host and a client side by side.

Roadmap

  • Server-authoritative movement, spawning, connection flow, replicated game state (architecture)
  • Custom URP shaders (player highlight, hit flash, dissolve)
  • Player prefab + Bootstrap scene wired in-editor
  • Materials + demo meshes using the shaders, with capture GIFs in this README
  • Client-side prediction / reconciliation on the player controller
  • Relay + Lobby (Unity Gaming Services) for online play beyond LAN
  • NGO integration tests (NetcodeIntegrationTest) covering spawn + ownership
  • Network profiler capture in the README (bandwidth per object)

License

See LICENSE.

About

Education Netcode and Shader test project

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors