0
0
Unityframework~10 mins

Lobby and matchmaking basics in Unity - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Lobby and matchmaking basics
Player opens game
Connect to server
Create or join lobby
Wait for players
Matchmaking starts
Players matched
Start game session
This flow shows how a player connects, joins or creates a lobby, waits for others, and then matchmaking pairs players to start a game.
Execution Sample
Unity
void Start()
{
    ConnectToServer();
    JoinOrCreateLobby();
    StartMatchmaking();
}
This code connects the player to the server, joins or creates a lobby, then starts matchmaking.
Execution Table
StepActionCondition/CheckResult/State ChangeOutput/Next Step
1Call ConnectToServer()Is server reachable?Connected to serverProceed to lobby
2Call JoinOrCreateLobby()Is lobby available?Joined existing lobbyWait for players
3Wait for playersEnough players joined?Players readyStart matchmaking
4Call StartMatchmaking()Match found?Players matchedStart game session
5Start game sessionGame ready?Game startedGameplay begins
💡 Game session started, matchmaking and lobby process complete
Variable Tracker
VariableStartAfter ConnectToServerAfter JoinOrCreateLobbyAfter Wait for playersAfter StartMatchmakingFinal
isConnectedfalsetruetruetruetruetrue
lobbyStatusnonenonejoinedjoinedjoinedjoined
playersReady000enoughenoughenough
matchFoundfalsefalsefalsefalsetruetrue
gameStartedfalsefalsefalsefalsefalsetrue
Key Moments - 3 Insights
Why do we check if the server is reachable before joining a lobby?
Because joining a lobby requires a connection to the server. As shown in step 1 of the execution_table, if the server is not reachable, we cannot proceed to join or create a lobby.
What happens if there are not enough players in the lobby?
The matchmaking does not start until enough players join. Step 3 shows waiting for players; matchmaking only starts when playersReady is 'enough'.
Can the game start before matchmaking finds a match?
No, the game starts only after matchmaking finds a match, as shown in step 4 and 5 where matchFound must be true before gameStarted becomes true.
Visual Quiz - 3 Questions
Test your understanding
Look at the variable_tracker table, what is the value of 'lobbyStatus' after JoinOrCreateLobby?
Anone
Bconnected
Cjoined
Dwaiting
💡 Hint
Check the 'lobbyStatus' row under 'After JoinOrCreateLobby' column in variable_tracker.
At which step in the execution_table does matchmaking start?
AStep 4
BStep 3
CStep 2
DStep 5
💡 Hint
Look for the action 'Start matchmaking' in execution_table.
If the server is not reachable, what happens to 'isConnected' variable?
AIt stays false
BIt becomes null
CIt becomes true
DIt becomes 'connected'
💡 Hint
Refer to 'isConnected' in variable_tracker after 'ConnectToServer' step.
Concept Snapshot
Lobby and matchmaking basics in Unity:
- Connect to server first
- Join or create a lobby
- Wait for enough players
- Start matchmaking to find matches
- Begin game session after match
Use server connection and lobby status variables to track progress.
Full Transcript
This visual execution shows the basic steps of lobby and matchmaking in Unity. First, the player connects to the server. Then they join or create a lobby. The system waits until enough players join the lobby. After that, matchmaking starts to find suitable players to play together. Once a match is found, the game session starts and gameplay begins. Variables like isConnected, lobbyStatus, playersReady, matchFound, and gameStarted track the state at each step. Key moments include ensuring server connection before lobby join, waiting for enough players before matchmaking, and starting the game only after a match is found.