How to Join a LAN Multiplayer Game using Netcode in Unity ECS

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 Join a LAN Multiplayer Game using Netcode in Unity ECS."

Full workflows and code to send and receive broadcast packets to join a multiplayer session on a LAN

Click Here for DOTS Tutorial

This gitbook takes you through step-by-step full workflows and code to send and receive broadcast packets to join a multiplayer session on a LAN. Once you've coded along and fully finished the "How To Join a LAN Multiplayer Game using Netcode" tutorial, you will be able to send and receive broadcast packets to join a multiplayer session on a LAN.

Click Here for DOTS Tutorial

High-Level steps to Join a LAN Multiplayer Game using Netcode:

Number 01

Create a new class for Udp Connection with methods to both send and receive UDP packets

Number 02

Create a script that pulls the broadcast IP address, port, and game name

Number 03

Create a new Game Object that listens for broadcast messages

FAQ

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

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 ECS?

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 ECS?

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