A practical guide to creating and managing game lobbies with code examples.
This guide provides a step-by-step walkthrough of how to use the PlayFlow Lobby SDK. We’ll cover setting up, creating, managing, and joining lobbies with practical code examples.For a high-level overview of the concepts, please see the Beginner’s Guide to Lobbies.
To use the lobby system, you must initialize it with a unique ID for the current player.
Unity
Unreal Engine
Godot
Add the PlayFlowLobbyManagerV2 component to a GameObject in your scene. Then, in a script, call the Initialize method.
using PlayFlow;using UnityEngine;public class GameInitializer : MonoBehaviour{ void Start() { // Use a unique ID for each player (e.g., from a login system or device ID) string myPlayerId = SystemInfo.deviceUniqueIdentifier; // Initialize the manager PlayFlowLobbyManagerV2.Instance.Initialize(myPlayerId, () => { Debug.Log("PlayFlow SDK is ready to use!"); }); }}
Players can join a public lobby by its ID or a private one with an invite code.
Unity
Unreal Engine
Godot
// Join by lobby IDstring lobbyIdToJoin = "... a lobby ID from the server list ...";PlayFlowLobbyManagerV2.Instance.JoinLobby(lobbyIdToJoin, onSuccess: (lobby) => Debug.Log("Joined lobby!"), onError: (error) => Debug.LogError(error));// Join by invite codestring inviteCode = "... a code shared by a friend ...";PlayFlowLobbyManagerV2.Instance.JoinLobbyByCode(inviteCode, onSuccess: (lobby) => Debug.Log("Joined private lobby via code!"), onError: (error) => Debug.LogError(error));
To build a server browser, you can fetch a list of all available public lobbies.
Unity
Unreal Engine
Godot
PlayFlowLobbyManagerV2.Instance.GetAvailableLobbies( onSuccess: (lobbies) => { Debug.Log($"Found {lobbies.Count} lobbies:"); foreach (var lobby in lobbies) { Debug.Log($" - {lobby.name} ({lobby.currentPlayers}/{lobby.maxPlayers})"); } // Now you can display this list in your UI }, onError: (error) => Debug.LogError(error));
After a match is started, all players in the lobby need to listen for the OnMatchRunning event. This event provides the IP address and port needed to connect to the game server.
Unity
Unreal Engine
Godot
void Start(){ // Listen for the server ready event PlayFlowLobbyManagerV2.Instance.Events.OnMatchRunning.AddListener(OnServerReady);}void OnServerReady(ConnectionInfo connectionInfo){ Debug.Log($"Server is ready! Connecting to {connectionInfo.Ip}:{connectionInfo.Port}"); // Use your networking library (Mirror, Netcode, FishNet, etc.) to connect here MyGameNetworkManager.Connect(connectionInfo.Ip, connectionInfo.Port);}
Use UpdatePlayerState to sync custom data for the local player, like their ready status or character choice. This data is automatically sent to all other players in the lobby.
Unity
Unreal Engine
Godot
public void SetReadyStatus(bool isReady){ var myCustomData = new Dictionary<string, object> { { "ready", isReady }, { "character", "Wizard" }, { "skin", "blue_robe" } }; PlayFlowLobbyManagerV2.Instance.UpdatePlayerState(myCustomData);}
Coming soon…
Coming soon…
To read another player’s data, you can access the lobbyStateRealTime dictionary from the CurrentLobby object.
Player state is self-owned. Hosts cannot push state onto other players. Each player updates their own state via UpdatePlayerState() and everyone reacts via OnLobbyUpdated. For team/role assignment, either have players pick their own team or broadcast assignments through UpdateLobbySettings() (host-owned) and have each client apply them locally.
Unity
Unreal Engine
Godot
var manager = PlayFlowLobbyManagerV2.Instance;if (manager.IsHost){ // Kick a player manager.KickPlayer("... some player id ..."); // Change the max players manager.UpdateLobby(maxPlayers: 8); // Broadcast team assignments through lobby settings (host-owned). // Each client reads lobby.settings["teamAssignments"] on OnLobbyUpdated. var assignments = new Dictionary<string, object> { { "teamAssignments", new Dictionary<string, string> { { "player_1", "blue" }, { "player_2", "red" } } } }; manager.UpdateLobbySettings(assignments);}