How to Keep Score in a Multiplayer Game with Netcode 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 Keep Score in a Multiplayer Game with Netcode in Unity DOTS."

Full workflows and code to keep score between players in a multiplayer game using Netcode

Click Here for DOTS Tutorial

This gitbook takes you through step-by-step full workflows and code to keep score between players in a multiplayer game using Netcode. Once you've coded along and fully finished the "How To Keep Score in a Multiplayer Game with Netcode" tutorial, you will be able to keep score between players in a multiplayer game using Netcode.

Click Here for DOTS Tutorial

High-Level steps to Keep Score in a Multiplayer Game with Netcode:

Number 01

Create both Player Score and Highest Score prefabs and components

Number 02

Update scores on server based on bullet collisions (who the sender is and what it collided with)

Number 03

Have clients update their Game UI based on updated ghost score values

FAQ

How do DOTS and MonoBehaviour work together within NetCode in Unity DOTS?

NetCode will be handling keeping track of scores of each player in the game. The idea is to take this data from ECS and populate the game UI which runs on MonoBehaviours. In our Tutorial, we demonstrate our approach to pulling data from ECS into MonoBehaviours by using the EntityManager. They key is to understand that a ECS System cannot "push" values directly into a GameObject, instead a MonoBehaviour must "pull" data using an EntityManager.

How do players find games using Netcode in Unity DOTS?

In order to do this in our tutorial, we will be using .NET's UdpClient class to send broadcast packets across the local area network's router. This will not work if the player is not connected to WiFi. We will also be using .NET's Thread class to create listening threads for broadcast packets so it does not interrupt Unity's threading.

What are some additional resources for how to use Netcode in Unity DOTS?

Unity documentation for Netcode 0.6.0-preview.7: https://docs.unity3d.com/Packages/com.unity.netcode@0.6/manual/index.html Refer to this for more information. Unity samples for NetCode: https://github.com/Unity-Technologies/multiplayer The Asteroids sample is what this gitbook is based off of. Unity thread for NetCode: https://forum.unity.com/threads/dots-multiplayer-discussion.694669/ Unity is responsive here.

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