Course contentsShow
← Unity Game Development
Lesson 806 of 82812. Multiplayer and DeploymentFree lesson

Developing Custom Lobby Systems for Player Grouping

Create and manage persistent lobby instances where players can gather, chat, and configure game settings before starting a match.

In this lesson, you will learn how to architect a persistent lobby system that allows players to aggregate, communicate, and modify game parameters before transitioning to an active game scene.

The Architecture of a Persistent Lobby

Unlike a match-session that exists only while the simulation is running, a lobby acts as a "waiting room" that persists across client connection cycles. In Netcode for GameObjects (NGO), you manage this by creating a dedicated LobbyManager using NetworkBehaviour.

This manager maintains a NetworkList of player metadata—such as player names, ready status, and selected loadouts—which is synchronized across all connected clients via NetworkVariable. Because the lobby exists before the match starts, you must ensure that your LobbyManager is placed in a scene that loads immediately after authentication, keeping it separate from the high-fidelity physics and game-logic scenes.

Handling Group Configuration

To allow players to configure settings, we use ServerRpc to update states and ClientRpc to broadcast changes to the UI. For instance, when a player changes their "Ready" status, the client sends a ServerRpc to the host. The host then updates a NetworkVariable that represents the collective readiness of the group:

public struct PlayerData : INetworkSerializable {
    public FixedString32Bytes PlayerName;
    public bool IsReady;
    // Implementation of NetworkSerialize omitted for brevity
}

public class LobbyManager : NetworkBehaviour {
    public NetworkList<PlayerData> playerList;

    [ServerRpc(RequireOwnership = false)]
    public void ToggleReadyServerRpc(ulong clientId) {
        // Update the list entry for the specific client
        // Syncing happens automatically via NetworkList
    }
}

By leveraging NetworkList and NetworkVariable, you ensure that late-joining players are instantly synchronized with the current configuration of the group. Once the host validates that all conditions are met—such as all players having IsReady set to true—they can trigger the transition to the game scene using SceneManager.LoadScene, ensuring the lobby data is passed or cached appropriately for the incoming match.

Key Takeaway: A custom lobby uses persistent NetworkVariables and NetworkLists to aggregate player state before the game session officially begins, ensuring all participants are synchronized before the match logic triggers.