Prerequisites
Before you write any lobby code, make sure you have:- The PlayFlow Unity SDK installed in your project.
- A PlayFlow project created in the dashboard, with your API key copied from the project’s settings. Use a client key (prefix
pfclient_) in game builds you ship to players — it is safe to embed. Keep server keys (prefixpf_) server-side only. - The SDK configured with that API key so it can reach the lobby API.
Initialize becomes the identity the lobby API trusts for that client. If you have configured a player-auth provider on your project, the SDK sends a verified player token instead and the player ID is derived from it.
Initial Setup (5 Minutes)
First, you need to get the Lobby Manager set up in your game.Step 1: Configure in Dashboard
Before you write any code, set up a lobby configuration in your PlayFlow project dashboard.- Go to your project’s Configuration → Lobbies tab.
- Create a new lobby configuration (e.g., “Default” or “Ranked”).
- Select the game server build and instance type this lobby will use.
- Save your configuration.
Step 2: Initialize the SDK
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.Basic Lobby Actions
Once the SDK is initialized, you can start performing lobby actions.Creating a Lobby
To create a new lobby, specify a name, the max number of players, and whether it’s private.- Unity
- Unreal Engine
- Godot
Joining a Lobby
Every lobby gets an invite code when it is created, public and private alike. Players can join a public lobby by its ID or by its code. Private lobbies can only be joined by code — a direct join by ID is rejected.- Unity
- Unreal Engine
- Godot
Listing Public Lobbies
To build a server browser, you can fetch a list of all available public lobbies.- Unity
- Unreal Engine
- Godot
Managing the Match
Starting a Match
When everyone is ready, the host can start the match. This will begin the process of launching a dedicated server.- Unity
- Unreal Engine
- Godot
Connecting to the Server
After a match is started, all players in the lobby need to listen for theOnMatchRunning event. This event provides the IP address and port needed to connect to the game server.
- Unity
- Unreal Engine
- Godot
Syncing Player Data
UseUpdatePlayerState 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
lobbyStateRealTime dictionary from the CurrentLobby object.
Host-Only Actions
Only the host of a lobby can perform sensitive actions:- Kicking a Player:
KickPlayer(playerId) - Updating Lobby Settings:
UpdateLobby(...)/UpdateLobbySettings(...)
Host is assigned automatically. There is no call to hand the host role to a specific player. When the current host leaves, host duty transfers automatically to the next player in the lobby (controlled by the lobby config’s
hostLeaveBehavior).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
Next Steps
Matchmaking Guide
Learn how to use the matchmaking system to find opponents automatically.
Lobby Events Reference
See a full list of all the events you can subscribe to for building a responsive UI.