Posted March 13, 2025 by Shivani
I focused on building the foundation of the multiplayer experience by creating a lobby system. With the Master Server connection already in place from my previous work, I was able to move forward with creating a functional lobby. The lobby acts as a central hub where players can browse available rooms or choose to create a new one, becoming the host.
The lobby is designed to give players flexibility and control over how they start a game session. It presents two main options:
Players can create a new room with a customised name. This allows them to set up a private or public session based on their preferences, offering more control over who they play with.
Players can join public rooms by browsing the available list. Each active room is displayed as a button in the UI - clicking on one of these buttons will instantly join the corresponding room, making it quick and easy to find a match.
Create Room Menu UI showing room settings
When a player decides to create a new room in the lobby, the OnCreateRoom() method is called. This function handles all the logic for setting up the room and sending a request to the Photon Master Server to actually create it.
A new RoomOptions object is created to define how the room should behave. To get things started, I used some default settings for the room.
The core of this function is the call to PhotonNetwork.CreateRoom():
To make it easy for players to find available rooms, I developed a Find Room Menu that displays a list of all joinable rooms currently available on the server. The UI dynamically updates the list when new rooms have been created or removed.
Find Room Menu UI showing an active room
In this script, a Room Item prefab will be instantiated on the UI everytime a room has been created. It assigns the player count and name of the room.
For every room in the roomList, a new UI object (RoomItem prefab) is instantiated inside the contentObject. This creates a dynamic list of rooms visible to the player.
The room's name and current player count are assigned to the newly created RoomItem through two simple setup functions:
Before displaying the room, the system checks if the room is already full:
Each instantiated RoomItem is added to a roomItemsList, allowing easy access later (e.g. refreshing or clearing the UI when the list updates).
Photon automatically sends updates whenever rooms are created, joined or closed. To handle these updates efficiently, I override the OnRoomListUpdate method:
To prevent updating the room list too frequently (which could cause performance issues), the room list only refreshes if enough time has passed (Time.time >= nextUpdateTime). This is controlled by a cooldown system using timeBetweenUpdates.
When the refresh condition is met, it calls UpdateRoomList(roomList), which re-renders the room list UI based on the latest room data.
To allow players to easily connect to an existing room, I build a RoomItem system where each available room is represented by a clickable button in the lobby UI. When a player clicks on one of these room buttons, they automatically attempt to join that specific room.
Here's how the system works in code:
RoomItem Script
Passing the Room Name
Joining the Room
4 players joining a room
The implementation of the Create Room Menu and Join Room Menu systems successfully met the expected outcomes and objectives set for this stage of development.
Room Creation
Dynamic Room List and Joining
The room list updates efficiently without unnecessary refreshes, helping maintain good performance even when multiple rooms are active.
After setting up the basic room creation and joining system, the next steps will focus on expanding and refining these features.
Private / Public Settings
Join via Room Name
Customisable Max Players
These updates will give players more control over how they play and connect with their friends, making the multiplayer experience more customisable.
[1] Photonengine. Setup and Connect (Version PUN 2). Available at: https://doc.photonengine.com/pun/current/getting-started/initial-setup.
[2] Photonengine. Introduction (Version PUN 2). Available at: https://doc.photonengine.com/pun/current/getting-started/pun-intro.
[3] Photonengine. Features Overview (Version PUN 2). Available at: https://doc.photonengine.com/pun/current/getting-started/feature-overview .