Skip to main content

Unreal Engine 5 Setup Multiplayer

✍ Last Updated : September 13, 2022

🚪 Prerequisite Knowledge (Optional)

Describe Initial Knowledge that reader need to know before reading this article

  1. Knowledge about Unreal Engine Multiplayer [Unreal Engine 5 Multiplayer](Unreal Engine 5 Multiplayer abd9e9eec78645d4bd8a52054a6ad115.md)
  2. Unreal Engine Multiplayer plugin, download here:

Sign in to your account

❓ Key Question / Problem / Issue

  1. How to setup Multiplayer in Unreal Engine Project?

✅ Expected Output/Definition of Done

  1. A project is set to be a Multiplayer game project

🎁 Resulting Solution

Setup Unreal Engine 5 Multiplayer

To setup project become a Multiplayer game is quite simple, because we already have a plugin to do all of sessions job, we just need to add it to the project. For now, the functions on the plugin that we have are create session, find sessions, cancel find sessions, join session, and destroy session.

Untitled

When the player clicks Create Lobby. Our code will configure the session settings and then call the session interface function create session. Once this is done, we can open the lobby level and wait for other players to join. Then when someone else starts the game and clicks Join Lobby, we'll configure some search settings, a set of properties that will help filter out any game sessions that we're not interested in joining. And then we'll call the interface function find sessions.

MultiplayerOnlineSubsystemGamePlan.png

This will return some search results and we'll iterate through those results and pick a valid session so we can then call the Join session. Once we've done this, we'll be able to get the proper IP address that we can use with the client travel function. Then use this function to travel over to the other players, listen server and join the lobby level with them.

Install multiplayer sessions plugin

Now, lets start to setup Multiplayer step by step with the sample project here.

  1. Add script at the bottom to implement online subsystem and steam support at Config/DefaultEngine.ini
[/Script/Engine.GameEngine]
+NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="OnlineSubsystemSteam.SteamNetDriver",DriverClassNameFallback="OnlineSubsystemUtils.IpNetDriver")

[OnlineSubsystem]
DefaultPlatformService=Steam

[OnlineSubsystemSteam]
bEnabled=true
SteamDevAppId=480

; If using Sessions
; bInitServerOnClient=true

[/Script/OnlineSubsystemSteam.SteamNetDriver]
NetConnectionClassName="OnlineSubsystemSteam.SteamNetConnection"
  1. Set the max player can join one session at Config/DefaultGame.ini
[/Script/Engine.GameSession]
MaxPlayers=8
  1. Place/install the downloaded multiplayer plugin to the project

    Untitled

  2. Before open the project, Generate Visual Studio project files first.

Untitled

  1. Re-build MultiplayerSessions plugin. Wait until the project is opened.

Untitled

  1. Check at Edit>Plugins, and search ‘multiplayer’ is plugins successfully installed, and ready to use.

Untitled

Implement multiplayer sessions plugin

Here, how the plugin is implemented on our UnrealShowcase project.

  1. Plugin folder usually not shown at default, at content drawer, you should go to Settings and check Show Plugin Content

Untitled

  1. There’s 2 folder at the plugin, Multiplayer Session C++ Classes & Multiplayer Sessions Content. Multiplayer Sessions Content is contains a Simple UI which have Host and Join button to quick test how the plugins work. But if you want to use custom UI for main menu, just ignore it and focus only on Multiplayer Sessions C++ Classes folder.

Untitled

  1. Open Multiplayer Sessions C++ Classes public folder, there’s **Menu** and **Multiplayer Sessions Subsystem.**Menu file is a base class for UserWidget to interact with MultiplayerSessionsSubsystem (If you need to call the Multiplayer Sessions Subsystem in a case on non widget blueprint, you still could directly call it, but not all function is exposed/just can be access only from Menu class).

Untitled

  1. To use Menu class you just need to set it as your widget parent, and you can directly access the session function

Untitled

Untitled

  1. In UnrealShowcase, we use Common Activable Widget UI (new UI stuff from unreal 5), so is not possible to set Menu as its parent since Menu type is UserWidget.So you can create it at MenuPlayerController, and Promote it as variable, so you can access it function through the MenuPlayerController then.

Untitled

  1. If you already have access to Menu, first, before using all of Menu functionality, call MenuSetup just like an image above. You need to define Number of Public Connection that can join in one sessions, type of match (default is FreeForAll) and define lobby path (Level). After that if you want to create a session just simply call HostButtonClicked, and to join session, call JoinButtonClicked function.
  2. If you need more implementation of Session just like cancel find session, you can access it directly from MultiplayerSessionsSubsystem just like this.

Untitled

  1. Open visual studio and go to Plugins/MultiplayerSessions to check all of functionality that currently exist and can be used.