How to use Multiplayer Sessions in your Unreal Engine 4 game

The Session System in Unreal Engine 4 gives you access to many powerful online features such as the server browser, setting a maximum player limits, setting private and public slots and much more.

Using this system is very straightforward and only takes a few blueprint nodes to get working.

In this guide I will show you how to setup multiplayer in Unreal Engine 4 using the session system. We will setup a simple session and connect to it through another player.

Starting a Multiplayer Session

Creating the Session

To start I created a simple widget with two buttons. One is host and one is play.

On the host button event use the create session blueprint node.

Creating the session

On the player controller pin, connect a “Get Player Controller” node and for the public connections pin set it to the maximum amount of players you want for this game.

Public connections is the maximum amount of players that can be connected to your server at once.

Adding the nodes to the Create Session node

If “Use Lan” is checked the session you create will be only available on your local internet.

Opening Levels to Multiplayer

To create a multiplayer game using your level, add a new “Open Level” node and set the “Level Name” pin to the level you wish to play on. In my case this is FirstPersonExampleMap.

Opening the level

The important step is to click the triangle at the bottom of this node to expose the extra settings.

Additional settings when opening the level

The “Absolute” checkbox and the “Options” text box pins are now visible. In the Options pin type exactly:

?listen

This code sets the level up to listen for multiplayer connections as a Listen Server.

Adding ?listen to the additional settings.

With these steps complete, the code should look like this.

Complete host code

Connecting to your Multiplayer Session

Finding Sessions

Finding sessions using blueprints is simple. The Find Sessions node handles all this for us. It outputs different execution pins based on if it succeeded or failed and the results that it found as an array.

If you aren’t familiar with arrays click here to learn about arrays in Unreal Engine 4.

To start I created the Find Sessions node attached to the Play button in my widget.

Find sessions node

On the player controller pin connect a “Get Player Controller” node and the Max Results pin is set to 100.

Adding nodes to the Find Sessions node

The Use Lan checkbox, if checked, will only search for sessions in your local area.

Joining the Session

To join a session in Unreal Engine 4, create a Join Session node.

This node requires the player’s controller and a session from the Find Sessions array in the previous step.

Join session node

Firstly I will create a Get Player Controller node and attach it to the Join Session node.

Adding the player controller to the Join Session node

From the Results output pin of the Find Sessions node in the previous step I created a Get node. This will find the first session in the list.

Getting session results from the Find Session node

This is then attached to the Search Results input pin of the Join Session node.

Attaching the found session to the join session node.

Finally, the Join Session node is attached to the On Success execution pin of the Find Sessions node.

Attaching the join session node to the on success pin of the find sessions node

Opening the Game Clients

In Unreal Engine 4, there is a drop down menu next to the play button which gives you access to multiplayer options.

On this menu make sure “New Editor Window (PIE)” is selected and the “Number of Players” slider is set to anything above 1.

Next, click the Advanced Settings button at the bottom of the menu.

Play settings in Unreal Engine 4

Near the bottom of the Advanced Settings menu, find the a section called Multiplayer Options.

Un-tick the checkbox “Auto Connect to Server”. This prevents the server auto connecting without the session system.

Advanced play settings

Finally, when you press the play button in your editor two clients will open.

Playing with two clients

The custom widget discussed earlier, displays the Host button and Play buttons.

On the first client I pressed the Host button. This reloaded the level.

Hosting the game

On the second client I pressed the Play button and waited until the Find Sessions node had finished searching for multiplayer sessions.

Once this finished it auto connected me into the first clients game.

Joining the game and showing two players connected to the same game

Connecting to Sessions Outside your Local Internet Network

The session created in this guide will can be used in your local network and through the internet.

If you connecting to a session in your local internet, you do not have to do anything else.

If you wish to host your session to global internet users, make sure to port forward UDP 7777. Setting up port forwarding is different per router so check your specific router instructions.

If you don’t know what port forwarding is click here.

Conclusion

Your multiplayer session is created and players can join!

This guide only brushed over the multiplayer system to start with sessions in Unreal Engine 4.

To learn more about replication and the session system, the Unreal Engine documentation as it is a good place to start.

Click here to read more about Replication.

Click here to read more about the session system nodes.

Expanding the System

To challenge yourself, try create a widget that fills itself with the results of the Find Session nodes.

This, if done correctly, will create a server browser similar to the ones found in games such as Team Fortress 2, Counter Strike and many more.

Image result for server browser tf2

Share your thoughts

4 Replies to “How to use Multiplayer Sessions in your Unreal Engine 4 game”

    1. Thanks. I’ve been busy recently but more tutorials are on the way. If you have anything specific that you would like me to make a tutorial on let me know through the contact page.

Leave a Reply

Your email address will not be published. Required fields are marked *