Lobby

The lobby is a set of classes that are designed to behave like a regular pre-game lobby would. You can use these lobbies as a waiting room for players before starting a match. This feature is entirely optional, as the lobby is not a core part of the plugin.

It is important to note that the lobby is the same as the "match" itself. It's a map hosted by the session host. If a player joins an online match that is already in progress (e.g. a Team Deathmatch), there will be no lobby to connect to as the host is already hosting the match itself.

Lobby Setup

  1. Create a new level.

  2. Create a new blueprint (or C++ class) for the following classes, and configure their variables:

    • KronosLobbyGameMode: Configure lobby wait times and the minimum player count required to start the match. Also, please make sure to select the proper Game State and Player Controller classes to be used once you've created them.

    • KronosLobbyGameState: Configure whether to relocate players. If enabled, players will be moved around locally between different Player Starts so that the local player can be in a fixed spot. The "Local Player Start Tag" variable determines the tag of the Player Start that should be used for the local player.

    • KronosLobbyPawn: Configure how the pawn looks. For example, you can add a Skeletal Mesh component so that a character model is visible to all players.

    • KronosLobbyPlayerController: Configure whether to override the view target or not. If enabled, the player will use a pre-placed Camera actor to view the lobby from. By default, the first available Camera will be used. The "Find Camera By Tag" variable can be used to specify which Camera to use as the view target.

  3. Override the game mode class to use for the level. Go to Window -> World Settings and set the "GameMode Override" variable to the blueprint (or C++ class) you created earlier.

  4. Place Player Start actors on the map. The amount of Player Starts required is based on the session's max player count.

  5. If you've enabled "Relocate Players" in the game mode, make sure that the Player Start which will be used by the local player is tagged properly. Select the Player Start in the editor and inside the Details window set the "Player Start Tag" to the same tag you determined in the game mode.

  6. If you've enabled "Override View Target" in the game state, make sure that a Camera actor is placed on the map. Please make sure that "Auto Activate for Player" is disabled on the Camera. Also, you may notice that black bars are visible for different screen resolutions. That's because "Constrain Aspect Ratio" is enabled by default on the Camera. Feel free to disable it.

  7. (Optional) Create a new blueprint and select KronosLobbyWidget as the parent class. The blueprint will turn into a Widget blueprint that you can edit in the UMG editor. This widget implements some helper functions and exposes a bunch of lobby events such as "On Lobby Updated", "On Player Is Ready Changed", "On Starting Match" and more. You can add this widget to the viewport in a "BeginPlay" event of a class. I recommend using the HUD class for this.

Setting Players Ready

When enough players are present in the lobby a countdown timer will be started. When all players are ready, the lobby will fast forward the countdown time and transition into the StartingMatch state.

Whether a player is ready or not is handled by the KronosLobbyPlayerState class. You can toggle the ready state of the player, or set it directly. Both functions are exposed to blueprints. In most cases, all you have to do is call TogglePlayerReady on the local player state. The ready state of the player will replicate down to all other players.

If you are using the KronosLobbyWidget then you can use the GetLocalPlayerState function to access the local player state casted into the correct type. This widget also contains the OnPlayerIsReadyStateChanged event which is called when the local player's ready state is changed.

Lobby Player Data

The KronosLobbyPlayerState includes a Player Data framework that automatically replicates an integer array to all players. This makes it very easy to advertise data about each player, such as their level, or the character / class they are going to play.

  • SetPlayerData: Used to set the player data. Overrides previous player data entirely.

  • GetPlayerData: Used to read the player data.

  • InitPlayerData: Can be used to set initial player data. Called when the player is initializing.

For example, lets say that players have to select a character in the lobby. You can make it so that each character is represented by an index, and the first element of the player data array is reserved for the character index. E.g. "Character A" = 1, "Character B" = 2, "Character C" = 3. If the player selects "Character B", set the first element of the player data array to 2. Later if you want to check which character the player is playing, you can get the first element of the player data array.

Updating Lobby Data

In most cases you'll want to update an existing session's settings (data) at some point. To update a session you'll have to get a copy of it's current settings, make the changes on the copy, and then push the changes to the session. The KronosOnlineSession class contains the necessary functionality to update sessions.

The lobby is considered a GameSession since it is part of an online match.

The Null Online Subsystem doesn't support updating data online, so only the local player will see the changes. For other limitations of the Null OSS please refer to Using the Null Subsystem section of the documentation.

Starting The Match

When enough players are present in the lobby and everyone is ready, the LobbyGameMode will transition into the MatchStarted state and the OnMatchStarted event will be called. The lobby can also be started immediately via the StartMatch function. Once the match is started, we can travel to a new map where the match will be played.

IMPORTANT: If the session uses reservations, make sure that the host reservation is set properly before changing maps! Please visit the Reservation page for more information about the host reservation.

Before traveling to the match, you can also update session settings as needed. For example if the map is selected randomly, you should update the "MapName" param in the session settings before traveling to the selected map.

We can travel to a new map by using the ServerTravel command. Blueprint projects can use the ServerTravelToLevel function to do this.

In packaged builds, you can only travel to maps that were included for packaging. You can do this by going to Edit -> Project Settings -> Packaging and in the advanced options look for the "List of maps to include in a packaged build".

NOTE: Short package names are fine while developing and testing inside the editor, but at some point you should use full path names for packages everywhere. In this case, I would have to change "MyMap" to "/Game/Maps/MyMap" given that the level is in a folder called "Maps".

Leaving The Lobby

You can leave a lobby at any time using a simple function call. The player will disconnect from the game and the session will be cleaned up automatically. If called on the hosting player, all clients will be gracefully disconnected before closing the game.

NOTE: The OnComplete event is called when the leave has been requested so at that time the player is still in the match (about to disconnect).

Last updated