How to Use NetCode with Player Prefabs in Unity DOTS

This will take you about 20 minutes in prep time if you don't have Unity set-up, and 30 minutes in coding and debug time.

Click Here for DOTS Tutorial

Stop struggling with the limited documentation. Follow this step-by-step tutorial: "How to Use NetCode with Player Prefabs in Unity DOTS."

Full workflows and code to turn a Player prefab into a NetCode ghost and spawn Thin Clients

Click Here for DOTS Tutorial

This gitbook takes you through step-by-step full workflows and code to turn a Player prefab into a NetCode ghost and spawn Thin Clients. Once you've coded along and fully finished the "How To Use NetCode with Player Prefabs" tutorial, you will be able to turn a Player prefab into a NetCode ghost and spawn Thin Clients.

Click Here for DOTS Tutorial

High-Level steps to Use NetCode with Player Prefabs:

Number 01

Add a GhostAuthoring component on Player prefab

Number 02

Store client inputs as Commands in a new input system

Number 03

Update targetEntity field to point at the spawned entity on the server

FAQ

What is Netcode in Unity DOTS?

Unity's DOTS NetCode is a dedicated server with client prediction networking model. Overview of Unity's decision to move to this type of network architecture, "Navigating Unity's multiplayer Netcode transition": https://blogs.unity3d.com/2019/06/13/navigating-unitys-multiplayer-netcode-transition/

What is the Server World and the Client World in Unity DOTS?

NetCode has a separation of client and server logic, and both the client and server logic are in separate Worlds (the client World, and the server World), based on the hierarchical update system of Unity’s Entity Component System (ECS). In Unity's authoritative server client-predicted network architecture, the server is the authoritative source of the game. So if the client "predicts" a response to an input and the server disagrees, the server wins.

What are Ghost entities in Unity DOTS?

"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". In Moetsi's sample project, Players, asteroid entities, and bullet entities will all be ghosts. Their state will be sent by the server to the clients by what unity calls "snapshots". Once the clients receive the snapshots the asteroids entities will have their state updated.

Haven’t begun learning Unity DOTS yet, and need to start at the very beginning?

If you haven't yet dipped your toes into learning Unity's new multithreaded Data-Oriented Technology Stack (DOTS), now is the time. You can start at the very beginning with Moetsi’s tutorial, which culminates in your very own deployable sample project. You’ll be guided by full workflows, code-alongs, videos, and GIFs along the way.

Get Started