Creating a Level Selector

This guide will show you how to manipulate the KronosHostParams at runtime to allow players to select which map they want to play on.

The guide will build on top of the Getting Started section directly, so it is assumed that you already have a basic understanding about how matchmaking works, and you already have a widget setup where you can start matchmaking from.

Setting Up The Level Selector Widget

1. Creating The Level Selector Widget

Let's start by creating the user interface of the level selector. Create a simple UserWidget blueprint and add Buttons to it which will represent the different maps that can be selected. Alternatively you can also use a ComboBox if you want to select the level from a dropdown menu instead.

2. Setting Up The Level Variables

Create two new String variables inside the widget:

  • SelectedLevelName: This will be used as the "Map Name" for matchmaking.

  • SelectedLevelPath: This will be the actual map that we travel to.

3. Modifying The Level Variables

Now we will update the level variables when the level buttons are clicked. I'm also going to hook up the OnInitialized event of the widget with the same logic as the first button to ensure that the level variables are never empty.

To make the selected level visible, we can change the tint of the buttons when they are clicked. Here is how you can tint the first button for example:

4. Creating the "Get Selected Level" Function

Create a new function named GetSelectedLevel. We will use this to easily access our level variables when filling out our matchmaking params. Make this a Pure Function by enabling the "Pure" option. This makes the node not require an execution pin. Also make sure that the function is public to make it accessible outside the widget.

5. Adding the Widget To The Screen

Add the level selector widget to the widget where your matchmaking buttons are located. In my case they are in the main menu widget so I will add it there and enable "Size To Content". Make sure to enable the "Is Variable" option on the widget to make it accessible in the blueprint graph.

Using The Level Selector

Now that we have the level selector in the same widget as the matchmaking buttons, we can switch over to the blueprint graph and update our matchmaking logic accordingly.

1. Get Selected Level When Creating The Match

Instead of filling out our host params manually by hand, we can now use the GetSelectedLevel function of the level selector widget that we created earlier.

To fix this, we will add a custom Session Setting to the session that will store the selected level. We can use the "Extra Session Settings" param of the KronosHostParams to easily add custom settings to the session. If you do not see this param, click on the little arrow at the bottom of the host params.

Let's use the FString as the type, and name it "GameLevel". We can also disable the "Advertise" option because this setting is only relevant to the hosting player.

Alternatively you could infer the map path from the "Map Name" param itself. The Sample Project for example uses a Data Table to determine which map path corresponds to the any given "Map Name".

2. Get Selected Level For Matchmaking

If you want to start matchmaming for the selected level, connect the level name to the "Map Name" param of your KronosMatchmakingParams. This tells the matchmaking system to find a match for the selected map.

3. Starting The Selected Level From The Lobby

Now all we have to do is simply get the selected level from the session when the match is being started in the lobby. Find the OnMatchStarted event of your KronosLobbyGameMode and use the GetGameSessionSetting function to get the selected level from the session.

Last updated