Intro to DOTS NetCode
Full workflows and code on how to get started with Unity's DOTS NetCode

What you'll develop in this in the NetCode section

Spawning and destroying ghosted objects and interacting with Thin Clients
We will spawn and destroy ghost entities and interact with Thin Clients through PlayMode Tools.

Functionalities included

    Navigating multiple ECS Worlds
    Creating a ECS NetworkConnectionEntity (NCE) on the client and server
      Creating a socket connection using NetworkStreamReceiveSystem
      Use GhostDistanceImportance component
    Sending RPCs between server and client
      Sending data with RPCs
      Using InvokeExecute on receiving NCE to make updates
    Loading a game on the client
      Using NetworkStreamInGame component
    Updating the CommandTargetComponent on a NetworkConnectionEntity
      Setting targetEntity field to ICommandData buffer
    Creating networked entities ("Ghosts")
      Ghost Authoring Component
        Updating Supported Ghost Modes
    Server-spawned entities
    Sending client inputs with ICommandData
      Predicted responses to ICommandData by using ClientSimulationSystemGroup.ServerTick
    Responding to ICommandData on both the client and server using GhostPredictionSystemGroup.ShouldPredict()
    Client-predicted entities and predicted-spawned entities
      Adding PredictedGhostSpawnRequestComponent
    Ghost classification systems
      Traversing GhostSpawnBuffer to locate predicted spawn entity
    Proper NetCode entity destruction
      Server-side destruction
      Using ISystemStateComponent component as a call back to clean up destroyed players

Unity DOTS NetCode

Unity's DOTS NetCode is a dedicated server with client prediction networking model. If that sentence made complete sense because you are aware of multiplayer game networking terminology and architectures you can skip the rest of this page and go right to the next section called "Create a Socket Connection."Otherwise if you don't, we highly recommend that you read through this section and read the content we link to throughout to get an understanding of multiplayer game networking. This code-along will go much more smoothly for you πŸ™‚πŸ™ƒ
Moetsi builds Reality Models, which can have thousands of networked objects in an environment. Although Unity's NetCode takes effort, the juice is worth the squeeze when building an XR experience with hundreds of live local players streaming the environment to remote players.
Next, read this break-down of key networking terms for a good overview of key concepts.
A blanket term used to describe the network programming of a game. It's basically a meaningless blanket term used to describe the network component of game programming. It is not a technical term.
From reddit post​
The quote is important to note to demonstrate that Unity NetCode is just Unity's implementation of multiplayer networking. It is not a technical term.
Read Gabriel Gambetta (the 🐐)'s Four-part post on Client-Server game architecture. Read all four parts. Seriously terrific.
From Gabriel Gambetta's blog series, a must-read.
Watch all of Timothy Ford's talk on ECS and NetCode to get a good understanding of what problems are being solved. If you must skip-out, at least just watch from 24:15 - 33:05.
Visual representation of "client being ahead of server" from Timothy Ford's talk
NetCode is no joke
Do not continue until "predicted-client" makes sense to you.
In this NetCode section of the gitbook, we will update the project we've been building in this gitbook so that instead of our client immediately acting on player input (like in InputMovementSystem and InputSpawnSystem), we will record "Commands" (which are basically Components of player input) and then send these Commands to the server to be played back.
In order for there to be immediate responsiveness on the client-side while the client is waiting for server commands, the client will also respond to these inputs by "predicting" what will happen (this is what's meant by "predicted-client" across all of the blog posts/videos we shared above).
Once the server runs the simulation, it will send back the results in "snapshots" of "ghosted" entities. "Ghost" is the Unity term for entities whose state the server sends to the client (a networked object). The server keeps track of all Ghosts and then sends "snapshots" of their Component's "Ghost Fields." Don't worry, you'll get used to all of this terminology.
In the updates we are about to make to our Project in the next sections of this gitbook, the asteroid, player and bullet entities will become Ghosts. Their state will be sent by the server to the clients via what Unity calls "snapshots." Once the clients receive the snapshots, the asteroid entities will have their state updated.

In this NetCode section, the focus will be on NetCode principles

The previous sections focused more heavily on how to implement ECS in general. In this section, we are assuming that you completed the previous section and/or that you have general grasp of Unity ECS. This section's focus will be on Unity's specific NetCode implementation.

Unity resources

Unity documentation for NetCode 0.6.0-preview.7:[email protected]/manual/index.html Refer to this for more information.
Unity samples for NetCode: The Asteroids sample is what this gitbook is based off of.
Unity thread for NetCode: The moderators from Unity are responsive here.
To best prepare for the following DOTS Physics code-alongs, we recommend that you complete the following check-list:
    ​Watch Timothy Ford's talk, at least from 24:15 - 33:05
    Understand authoritative server client-predicted networking model
    Have a general understanding of Unity ECS and are familiar with the previous two sections
Last modified 7mo ago