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

Synchronizing Lobby Metadata and Player Properties

Update lobby states in real-time to track player readiness, custom team assignments, and shared match configuration variables.

In this lesson, you will learn how to maintain shared state across your lobby using Data dictionaries to track player readiness and team configurations before a match begins.

Beyond the NetworkVariable

While NetworkVariable is perfect for syncing continuous data (like health or position) during an active match, the Lobby service acts as the "waiting room" before your NetworkManager fully takes over. Synchronizing lobby metadata requires managing two distinct layers: Lobby Data (the state of the game room) and Player Data (the state of individual participants).

When a player changes their "Ready" status or switches their team, you must update the Lobby object’s PlayerData dictionary. Because the Lobby service lives on the cloud, these changes are pushed to all connected clients via the Unity Gaming Services SDK.

Managing Player Properties

To track if a player is ready, you store a key-value pair within the PlayerData object. When the player clicks a UI toggle, you send an update request to the Lobby service:

// Example: Updating a player's readiness status
Dictionary<string, PlayerDataObject> data = new Dictionary<string, PlayerDataObject>
{
    { "IsReady", new PlayerDataObject(PlayerDataObject.VisibilityOptions.Member, "true") }
};

await Lobbies.Instance.UpdatePlayerAsync(lobbyId, playerId, new UpdatePlayerOptions { Data = data });

Syncing Shared Configuration

Lobby metadata is used for shared match variables, such as the selected map or game mode. Unlike NetworkVariable, which handles rapid replication during gameplay, these lobby properties are typically updated less frequently. By updating the Lobby object’s Data dictionary, every client receives a lobby update notification. You should hook into the OnLobbyEventCallbacks to refresh your UI whenever a metadata change is broadcast, ensuring that all players see the same map selection and team distribution in real-time.

By decoupling your setup phase (Lobby) from your gameplay phase (Netcode), you avoid overloading your game server traffic with data that only needs to be known while the players are still choosing their loadouts.

Key Takeaway: Use Lobby PlayerData for per-user settings like readiness and Lobby.Data for shared match variables to maintain consistency before the game session formally begins.