Skip to main content

Network Modes

Online

Default selection. This is trying to connect to a dedicated or cloud matchmaking servers for automatic match creation and joining as described in the Matchmaking section, which is the simplest way to get right into a battle and play against other players. The timeout for finding and joining a match is set to 10 seconds, which could be reached due to connectivity or device networking issues.

With Netcode, for the Online mode you can either host your own server or use an external provider. If you want to use your own server, you have to set its IP address in the Unity Transport component, so the NetworkManagerCustom is aware where to connect to.

NetworkMode010

Without an own server, you need to somehow ensure your players can host and join online games on their own. For this, you will want to use a service. Unfortunately, Unity does not provide public matchmaking servers in Netcode by default, but using their separate Unity Relay and Matchmaking services. Lobby offers the functionality to discover other players looking for the same game mode (before being in a match), while Relay then routes all network traffic over a public Unity server (in a match). This is a paid Unity service and you can find more information about it on the official documentation pages.

In this asset, support for Unity Relay and Lobby is already built-in but needs to be enabled. For a short guide on how to do this, please see How To: Enable Unity Relay and Lobby.

If you are looking for free online matchmaking instead, I would recommend checking out the Steamworks or Epic Online Services transports. An Epic Online Services guide for Netcode will be considered in a future documentation update!

Local Area Network

LAN mode does not forward traffic to the public or cloud servers, but rather keeps it locally in a private network, where only other devices in the same network are able to host and join a battle. A common use case is hosting a game that can only be joined by your friends who sit next to you.

This asset supports local discovery using the .NET UdpClient class in order to detect other devices in the same network and join a game automatically. If no match can be found after exceeding the timeout value, then the searching device creates a new LAN match itself. Note that on Windows/Mac LAN mode requires disabling firewalls for detecting other devices.

Offline

Playing against bots. This mode is simulated by creating a private LAN game, but without making it public for other devices, by setting the allowed connection count to 1. The big advantage of this is that there are no changes to existing network code necessary. Bots are controlled by the PlayerBot class, a derived script of the Player class, which uses Unity's navigation system for movement. Note that bots do not exist in a network, they are purely offline, so adding them to e.g. a LAN game would not work.