Player Zero
  • Welcome
  • Integrations
    • Unity Integration
      • Deeplinking
      • Player Zero Lobby
      • 🎮 QuickStart Sample
    • Direct API Integration
Powered by GitBook
On this page
  • 🧩 What Player Zero provides to your game
  • 🛠️ How to use this in Unity
  • Summary
Export as PDF
  1. Integrations
  2. Unity Integration

Player Zero Lobby

The Player Zero platform allows players to form pre-game lobbies with their friends, then launch your Unity game together with synchronized session data.

When a host starts the game from the Player Zero website, the game is launched with metadata that helps your game:

  • Identify the lobby (lobbyId)

  • Determine who is the host (host)

  • Match all players to the correct region (region)

This page explains how to read this data inside your Unity project and use it to connect all players to the same multiplayer session, especially when using a networking solution like Photon.


🧩 What Player Zero provides to your game

When the game is launched from a Player Zero lobby, the following parameters are passed:

Parameter
Type
Description

lobbyId

string

A shared ID for the session. Can be used as the room name or lobby code.

host

boolean

Indicates whether the current player is the lobby host.

region

string

The region code for the session (e.g., us, eu, etc). Use this to ensure all players connect to the same region and prevent connection issues.


🛠️ How to use this in Unity

The Player Zero SDK includes a helper class called ZeroLobby that makes it easy to retrieve lobby data passed from the Player Zero platform.

You can use it to:

  • Check if lobby data is available LobbyQueryHandler.CheckForLobby()

  • Get the lobby ID LobbyQueryHandler.LobbyId

  • Check if the player is the host LobbyQueryHandler.IsHost

  • Get the region of the host LobbyQueryHandler.HostRegion

Call LobbyQueryHandler.CheckForLobby() early in your game's startup flow to initialize and apply the correct values.

For example you might have a NetworkManager class that checks for a lobby in the Start function.

using PlayerZero.Runtime;
public class NetworkManager 
{

    private void Start()
    {
        if(LobbyQueryHandler.CheckForLobby())
        {
            //Lobby parameters found, setup in game network room or lobby
        }
    }
}

The following code samples are using API's from Photon PUN2 networking plugin but the concepts should be the same for any Unity networking solution.

1. Use lobbyId as your room name

This ensures that all players connect to the same room or lobby.

PhotonNetwork.JoinOrCreateRoom(LobbyQueryHandler.LobbyId, new RoomOptions(), TypedLobby.Default);

2. Use LobbyQueryHandler.IsHost to determine role

If LobbyQueryHandler.IsHost == true, the player should create the room. Otherwise, they should join the room.

if (LobbyQueryHandler.IsHost) //host will create room while others will join room
{
    PhotonNetwork.CreateRoom(LobbyQueryHandler.LobbyId, new RoomOptions(), TypedLobby.Default);
}
else
{
    PhotonNetwork.JoinRoom(LobbyQueryHandler.LobbyId);
}

3. Use region to connect to the correct server

Photon normally selects a region based on the player's location. You'll want to force all players to use the host's region to prevent mismatched rooms.

PhotonNetwork.PhotonServerSettings.AppSettings.FixedRegion = LobbyQueryHandler.HostRegion;
PhotonNetwork.ConnectUsingSettings();

4. Optionally send players back to Player Zero after the game ends

If you're building a WebGL game, the SDK includes a function that allows you to return players back to the Player Zero lobby after a game session ends

To trigger this behavior from your Unity code, call the following method:

// playerScore is an int value that represents the players score.
// the score is used to determine which member of the lobby is the "winner" of the game
// if score is not applicable to your game then you can just send 0
PlayerZeroSDK.SendBackToPlayerZero(playerScore);

Calling this will exit the game view and return the player to the Player Zero lobby interface.


Summary

By using lobbyId, host, and region, you can ensure:

  • All players join the same room

  • The correct player creates the room

  • Everyone connects to the same region

This approach ensures a consistent multiplayer experience across all participants, especially when using cloud-based networking solutions like Photon.

PreviousDeeplinkingNext🎮 QuickStart Sample

Last updated 1 month ago