Unity / C# integration
Lobby, leaderboard and relay servers for Unity.
Connect your Unity game to Berries through C# HTTPS requests and JSON. Use a free lobby server, leaderboard server and optional UDP relay for your first registered game, subject to per-game capacity limits.
One registered game per free account. Per-game capacity limits apply.
Start with a game ID and a UnityWebRequest client
Register your game in the developer portal, enable the features you need and copy its game ID. The portal includes Unity C# request examples alongside Unreal and Godot samples. You can also call the HTTP API directly; this is an API integration rather than a prebuilt Unity transport package.
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
public static class LobbyBrowser
{
public static IEnumerator BrowseLobbies(string apiUrl, string gameId)
{
var url = $"{apiUrl.TrimEnd('/')}/games/{Uri.EscapeDataString(gameId)}/lobbies";
using var request = UnityWebRequest.Get(url);
yield return request.SendWebRequest();
if (request.result == UnityWebRequest.Result.Success)
Debug.Log(request.downloadHandler.text); // Parse and render your lobby list.
else
Debug.LogWarning($"Lobby discovery failed: {request.responseCode}");
}
}
Call BrowseLobbies from a MonoBehaviour with StartCoroutine, supplying the configured API URL and your game ID. Handle HTTP errors and parse the response into your own lobby-browser model before letting a player select a session.
Unity lobby server: discover, join and maintain sessions
Use UnityWebRequest to create or list lobbies through the game's lobby endpoint. Joining a lobby returns a member token and host connection information. Store the token for heartbeat and member operations, and render host-published player counts and joinability in your UI.
Your Unity netcode still owns simulation and replication. After joining, connect your transport to the returned endpoint. If your quick-play UI should select a lobby for the player, use the matching endpoint to join or create one.
Explore lobby server capabilities →Unity leaderboard server: scores, times and run data
Enroll a player once, securely retain the returned bearer token and use it for leaderboard calls. This token is separate from lobby credentials. Create leaderboard definitions in the portal, then retrieve entries to populate your Unity ranking screen.
Send scores as decimal strings and times as whole microseconds. Upload results as multipart requests containing entry JSON and a userData part, which may be empty. Reuse each run's Idempotency-Key and request body on retries to avoid duplicate processing. Your game implements validation and any recording or replay format.
Explore leaderboard server capabilities →Unity relay server: adapt your UDP transport
When your connection strategy needs relay, the host provisions a relay session through HTTPS and joining members request access. Implement the relay's UDP packet framing, authentication, binding and keepalives in your transport adapter. The portal documents the packet protocol.
Peer rendezvous can help attempt direct connectivity from the same socket, with relay remaining available. This requires a platform that supports the UDP transport you implement; it does not make a browser-only Unity WebGL client UDP-capable. Berries is an independent service and is not Unity's Lobby or Relay product.
Explore UDP relay server capabilities →