Lesson 2: Netcode Package Choice and Project Setup (NGO and Transport Stack Baseline)

Now that scope is locked, your next win is a stable networking baseline. This lesson helps you choose one practical package stack and set project defaults that every teammate can reproduce.

Lesson Objective

Ship a clean multiplayer project bootstrap with:

  1. Netcode stack decision (NGO + transport baseline)
  2. Package versions pinned for team consistency
  3. Startup scene and network bootstrap object
  4. One checklist for local host-client smoke tests

Why This Matters

Most early multiplayer churn is not gameplay code. It is environment mismatch: different package versions, missing transport settings, or startup scenes wired differently per machine.

You fix that here before building connection lifecycle logic in Lesson 3.

Quick decision matrix

Use this lightweight matrix for your vertical slice:

Option Fit for this course Tradeoff
NGO + Unity Transport (direct/local) Best default for fast slice iteration Limited NAT traversal out of the box
NGO + Unity Transport + Relay later Good production path for friends-and-family tests Adds service setup and auth flow complexity
Custom transport first Usually overkill for a 15-lesson slice Slower onboarding and debugging

Recommended choice now:

  • NGO + Unity Transport, with relay readiness deferred to later integration checkpoints.

Step-by-step setup

Step 1 - Install and pin core packages

In Package Manager, add and pin:

  • com.unity.netcode.gameobjects
  • com.unity.transport

Then save versions to lockfile and commit immediately. Do not let teammates auto-upgrade mid-sprint.

Step 2 - Create multiplayer startup scene

Create one scene named BootstrapMultiplayer.

Scene requirements:

  • Empty root object: NetcodeBootstrap
  • NetworkManager component attached
  • Transport component assigned to the same object
  • One placeholder player prefab registered in NetworkPrefabs

Keep this scene tiny. It is an initialization harness, not gameplay.

Step 3 - Configure default host-client test flow

Add temporary UI buttons or debug keybinds:

  1. Start Host
  2. Start Client
  3. Shutdown

Your goal is repeatable startup and teardown, not production UI.

Step 4 - Define transport-stack notes

Record a one-page transport note in project docs:

  • Current mode: local/direct transport for iteration
  • Future mode: relay-enabled for remote playtests
  • Constraints: expected player count, expected region assumptions

This note prevents confused “why no remote join” bugs when testing scope is still local.

Step 5 - Run the bootstrap checklist

Before writing gameplay replication:

  1. Start host in one editor instance.
  2. Start client in second instance or build.
  3. Confirm connection success and one spawned player object.
  4. Shutdown host and confirm client disconnect behavior.
  5. Restart in reverse order and repeat once.

If any step fails, fix setup before proceeding to lifecycle work.

Practical bootstrap script

using Unity.Netcode;
using UnityEngine;

public class NetcodeBootstrap : MonoBehaviour
{
    public void StartHost()
    {
        if (!NetworkManager.Singleton.IsListening)
            NetworkManager.Singleton.StartHost();
    }

    public void StartClient()
    {
        if (!NetworkManager.Singleton.IsListening)
            NetworkManager.Singleton.StartClient();
    }

    public void Shutdown()
    {
        if (NetworkManager.Singleton.IsListening)
            NetworkManager.Singleton.Shutdown();
    }
}

Mini challenge

Create a README-multiplayer-bootstrap.md in your project root that includes:

  • Exact package versions
  • Scene name
  • Host/client launch steps
  • One known limitation (for example: local network only, no relay yet)

Hand it to a teammate and ask them to reproduce your setup in under 10 minutes.

Pro tips

  • Keep one dedicated bootstrap scene separate from gameplay scenes.
  • Commit package changes in isolated PRs to simplify rollback.
  • Prefix temporary networking scripts with NetDebug or Bootstrap so cleanup is obvious later.

Common mistakes

  • Installing NGO but forgetting to assign transport in NetworkManager
  • Mixing experimental package versions between teammates
  • Building gameplay systems before host-client connect/disconnect is stable

Troubleshooting

"Host starts but client never connects."

Verify transport component assignment and ensure both instances use the same address/port defaults.

"Player prefab is not spawning."

Confirm the prefab is registered under NetworkPrefabs and includes a NetworkObject.

"Everything works once, then breaks after stop/start."

Check teardown path and ensure Shutdown() is called before restarting mode.

Recap

You now have a reproducible NGO + Unity Transport baseline with package pins, bootstrap scene, and smoke checklist. That foundation keeps your networking branch stable while gameplay features grow.

Next lesson teaser

Lesson 3 covers player spawn and connection lifecycle, including approval flow and clean disconnect handling so sessions do not leak state.

Related links

Bookmark this lesson before your next setup pass, and share the bootstrap checklist with your team to keep environment drift out of your multiplayer sprint.