Intro to DOTS NetCode
Full workflows and code on how to get started with Unity's DOTS NetCode
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.
- 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'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.
NetcodeA 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.
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.
From Gabriel Gambetta's blog series, a must-read.
Visual representation of "client being ahead of server" from Timothy Ford's talk
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.
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.
To best prepare for the following DOTS NetCode code-alongs, we recommend that you complete the following check-list:
- Understand authoritative server client-predicted networking model
- Have a general understanding of Unity ECS and are familiar with the previous two sections
NOTE IF STARTING FROM THIS SECTION (and you haven't done of the previous sections)
You will need to add this to the Player Settings!