(v0.50) DOTS Tutorial - Build a Multiplayer AR app
  • What is the Purpose of this DOTS Tutorial?
  • Important Notes For Using This Gitbook
  • Unity ECS
    • Intro to Unity ECS
    • Create a Unity ECS Project
    • Spawn and Move Prefabs
    • Spawn and Move Players
    • Spawn Bullets and Destroy Player
    • Publish Builds in Unity ECS
  • Unity DOTS Physics
    • Intro to Unity DOTS Physics
    • Use DOTS Physics for Prefabs, Players, and Bullets
    • Use DOTS Physics for Collisions
  • Unity DOTS NetCode
    • Intro to DOTS NetCode
    • Create a Network Connection using DOTS NetCode
    • Load a Game using DOTS NetCode
    • DOTS NetCode and Prefabs
    • DOTS NetCode and Player Prefabs
    • Use DOTS NetCode for Collisions and Destroying Bullet Prefabs
    • Dynamically Changing Ghosts Between Interpolated and Predicted
  • UI Builder and UI Toolkit
    • Intro to UI Toolkit
    • Create a ScreenManager
    • Style a View
    • Create a ListView
    • Responsive Game UI
    • Navigate Between Scenes Using ClientServerBootstrap
  • Multiplayer (NetCode+, UI Toolkit+)
    • Intro to Unity NetCode Multiplayer
    • Host or Join a Multiplayer Session on LAN
    • Broadcast a LAN Multiplayer Game
    • Keep Score and Update Game UI
    • Send Ghosts with NetCode Using Relevancy
  • AR Foundation
    • Intro to AR Foundation
    • Set Up AR Foundation and ARKit
    • Spawn a Player using AR Foundation
    • Update UI using AR Foundation
Powered by GitBook
On this page
  • What you'll develop in this in the NetCode section
  • Functionalities included
  • Unity DOTS NetCode
  • In this NetCode section, the focus will be on NetCode principles
  • Unity resources
  1. Unity DOTS NetCode

Intro to DOTS NetCode

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

PreviousUse DOTS Physics for CollisionsNextCreate a Network Connection using DOTS NetCode

Last updated 2 years ago

What you'll develop in this in the NetCode section

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.

Netcode

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.

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.

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

To best prepare for the following DOTS NetCode code-alongs, we recommend that you complete the following check-list:

NOTE IF STARTING FROM THIS SECTION (and you haven't done of the previous sections)

Github branch link:

First, start by reading

Next, read this for a good overview of key concepts.

From

Watch this .

Read Gabriel Gambetta (the 🐐)'s . Read all four parts. Seriously terrific.

Watch 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.

Unity documentation for NetCode 0.6.0-preview.7: 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.

, at least from 24:15 - 33:05

You will need to add this to the Player Settings!

https://github.com/moetsi/Unity-DOTS-Multiplayer-XR-Sample/tree/Updating-Bullets-and-Destruction
Join our Discord for more info
Unity's blog post on their decision to move to NetCode network architecture, "Navigating Unity's multiplayer NetCode transition."
break-down of key networking terms
reddit post
video explaining lag compensation and interpolation delay
Four-part post on Client-Server game architecture
all of Timothy Ford's talk on ECS and NetCode
Watch Timothy Ford's talk from 24:15 to 33:05, seriously.
https://docs.unity3d.com/Packages/com.unity.netcode@0.6/manual/index.html
https://github.com/Unity-Technologies/multiplayer
https://forum.unity.com/threads/dots-multiplayer-discussion.694669/
Watch Timothy Ford's talk
Join our Discord for more info
Spawning and destroying ghosted objects and interacting with Thin Clients
From Gabriel Gambetta's blog series, a must-read.
Visual representation of "client being ahead of server" from Timothy Ford's talk