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).
Authenticate the player using UnityServices.InitializeAsync() and AuthenticationService.Instance.SignInAnonymouslyAsync() before calling any Lobby or Relay APIs.
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.
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.
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.
Implement a heartbeat loop calling LobbyService.Instance.SendHeartbeatPingAsync at intervals shorter than the lobby idle timeout to prevent automatic deletion.
Known gotchas
Relay allocations expire if not joined within a short window after creation; the host must pass the JoinCode to the lobby before clients attempt to connect.
Lobby queries are rate-limited; implement exponential backoff on the client when polling for lobby updates rather than querying at a fixed high frequency.
The host leaving the lobby does not automatically migrate host status; implement host migration logic or use a dedicated server model for sessions where host dropout must be handled gracefully.
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp