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
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
Ghost classification systems
Traversing GhostSpawnBuffer to locate predicted spawn entity
Proper NetCode entity 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.
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.