Skip to main content

Enable Unity Relay and Lobby

This guide explains how to enable the Unity Services Relay and Lobby for Netcode in Tanks Multiplayer. Unity Gaming Services offer a generous free limit for these services with paid pricing after exceeding them. Please see the official documentation pages for more details on them.

Problem description

When using Unity Netcode, it does not provide matchmaking servers by default. So if you are not hosting your own public server, players will not be able to play together in Online mode. In order to enable your players to host and find games themselves when playing online, you will want to get rid of any firewall and NAT traversal issues by using Unity Relay and Lobby services.

Enable Services

Navigate to the Unity Gaming Services dashboard and select your project in the dropdown list at the top of the page. If you cannot find your project in this list, you have to create an entry for your project first. In Unity, open Window > General > Services or have a look at the little cloud icon in the top right corner and follow its instructions.

With your project selected, click on Multiplayer in the sidetab. You will see another tab with Unity Services, namely Relay and Lobby. Click on both sections and follow the instructions to enable them.

UnityRelay010

UnityRelay020

When enabling the Service, make sure to set the Maximum player slots field in the Lobby Config equal to the Max Players value in Unity, on the NetworkManagerCustom component.

UnityRelay030

Afterwards, import Relay and Lobby packages in Unity.

UnityRelay040

Adding the Scripting Define

Enable Netcode's usage of the Unity Services by adding the NETCODE_UGS define to your platform via Edit > Project Settings > Player > Other Settings > Script Compilation and press Apply.

UnityRelay050

That's it! When playing in Online mode, your game will now make use of Unity Gaming Services for hosting and playing.