Set up Unity Lobby and Relay services for peer-to-peer multiplayer with NAT traversal

domain: unity.com · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Enable the Lobby and Relay packages in the Unity Gaming Services dashboard and install them via the Package Manager (com.unity.services.lobby and com.unity.services.relay).
  2. Authenticate the player using UnityServices.InitializeAsync() and AuthenticationService.Instance.SignInAnonymouslyAsync() before calling any Lobby or Relay APIs.
  3. The host calls RelayService.Instance.CreateAllocationAsync(maxConnections) to get a relay allocation, then encodes the JoinCode and passes it as a lobby data attribute when creating the lobby via LobbyService.Instance.CreateLobbyAsync.
  4. Joining players query or quick-join via LobbyService, read the JoinCode from lobby data, then call RelayService.Instance.JoinAllocationAsync(joinCode) to obtain relay connection details.
  5. Pass relay allocation data (server endpoint, connection data, key) to your Netcode transport (e.g., UnityTransport) to establish the peer-to-peer connection through the relay.
  6. Implement a heartbeat loop calling LobbyService.Instance.SendHeartbeatPingAsync at intervals shorter than the lobby idle timeout to prevent automatic deletion.

Known gotchas

Related routes

Create and find a Unity Gaming Services Lobby and connect players via Relay for peer-to-peer transport
docs.unity.com · 6 steps · unrated
Implement Unity Gaming Services Lobby and Relay for peer-to-peer multiplayer
unity.com · 6 steps · unrated
Establish NAT-traversing peer-to-peer connections using the Epic Online Services P2P interface
dev.epicgames.com · 5 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans