Sessions and hosting

Host and join a co-op session from code or the command line, run a lobby between runs, handle players, kicks, rejoin and map travel.

Last updated Oct 26, 2026Edit this pageVersion 1.0.0

FNetSession is the object your game talks to. It owns the host, join and leave state machine, one player record per connection, a pawn per player, the lobby phase and the gameplay event channel. It is a process singleton (FNetSession::Get()), and ReplicationManager ticks it for you every frame FNetSession.

Host a session

Call HostSession with a world and settings. Pass an MWorld* for an actor-based game, or an ECS World* for a headless driver.

StartCoop.cpp
#include "Core/Platform.h"
#include "Networking/Session/FNetSession.h"
#include "Networking/Session/NetSessionTypes.h"

#include <string>

static bool StartCoop(Mowo::MWorld* world, const char* playerName) {
	Mowo::FNetSessionSettings settings;
	settings.sessionName = "Scan Team";
	settings.playerName = playerName;
	settings.maxPlayers = 4;
	settings.port = 7777;
	settings.lateJoinPolicy = Mowo::ENetLateJoinPolicy::LobbyOnly;

	return Mowo::FNetSession::Get().HostSession(world, settings);
}

static bool JoinCoop(Mowo::MWorld* world, const char* hostAddress, const std::string& joinKey, const char* playerName) {
	Mowo::FNetSessionSettings settings;
	settings.playerName = playerName;
	settings.joinKey = joinKey;

	return Mowo::FNetSession::Get().JoinSession(world, hostAddress, 7777, settings);
}

The hosting player is admitted as player 1 on peer 0 and gets a pawn of its own unless spawnHostPawn is off. For each player, the host spawns a pawn in this order:

  1. If the world has an AGameMode, through AGameMode::RestartPlayer, possessed by a per-player controller (see Gameplay).
  2. Otherwise, the class set with SetPlayerPawnClass.
  3. Otherwise, a bare entity with a transform and a NetworkObjectComponent.

The pawn is marked always relevant and owned by that player's peer. playerPawnPrefab names the prefab clients instantiate for the ghost.

Join keys

A direct (ENet) session joined from another machine needs the host's join key. GetJoinKey() on the host returns <address>:<port>#<key>; show it in your lobby UI and pass the key in FNetSessionSettings::joinKey when joining FNetSession::GetJoinKey. The key is empty on loopback, for Steam joins, and when the session authenticates through a configured net.psk instead. See Transport and encryption.

Settings

FNetSessionSettings FNetSessionSettings:

FieldDefaultMeaning
sessionName"Mowo Session"Name shown in rich presence and lobbies
playerName"Player"This player's display name
playerPawnPrefabemptyPrefab clients use for player ghosts
port7777ENet port. Not used on the Steam P2P route. 0 picks a free port.
joinKeyemptyThe host's join key, when joining a direct session from another machine
maxPlayers5Host included. Joins past this fail with ServerFull.
snapshotHz20Snapshot rate
interpolationDelay0.10Seconds remote objects are drawn behind
connectTimeoutSeconds15Client connect deadline
travelAckTimeoutSeconds60How long the host waits for clients after map travel
relevancyEnabledtruePer-client relevancy
spawnPlayerPawns, spawnHostPawntrue, trueWhether the session spawns pawns, and whether the host gets one
createSteamLobbyfalseCreate and advertise a Steam lobby
advertiseRichPresencetruePublish the session to platform presence
maxUpdatesPerTick, maxSnapshotBytes64, 1200Per-client snapshot caps
peerByteBudgetPerSecond6000Outgoing bytes per second per client
hostUplinkBytesPerSecond30000Host uplink shared by all clients. 0 means no host-wide cap.
peerInboundByteBudgetPerSecond8192Incoming bytes per second per client
playerCullDistance, playerNetPriority0, 8.0Relevancy radius and send priority of player pawns
rejoinGraceSeconds-1Seconds a dropped player's slot is held. Negative follows net.rejoin_grace_seconds (60). 0 disables.
lateJoinPolicyAnytimeLobbyOnly refuses new players while a run is in progress
autoRejoinAttempts, autoRejoinDelaySeconds3, 2How often and how far apart a dropped client retries on its own

Session state

GetState() returns an ENetSessionState: Idle, Hosting, Connecting, Connected or Failed. SetOnStateChanged observes every change. When a session fails, GetFailure() says why ENetSessionFailure:

FailureMeaning
NoTransport, HostFailed, ConnectFailedThe transport could not start or reach the host
TimeoutNo welcome within connectTimeoutSeconds
ServerFullmaxPlayers reached
DisconnectedThe link dropped
ContentMismatchThe client's content build or DLC set differs from the host's
Kicked, BannedThe host removed this player
ProtocolMismatchThe host runs a different replication protocol or component schema
HostEndedSessionThe host closed the session on purpose
HostLostThe link to the host dropped and every automatic rejoin attempt failed
RunInProgressThe host only takes new players in the lobby, and a run is under way

GetLastJoinRefusalReason() and GetLastExitReason() hold readable reasons for the UI. When a client's session ends for good (host left or lost, kicked, banned, build mismatch), the runtime returns it to the project's start scene through SetOnReturnToMenu. There is no host migration.

Note

Builds other than release and profile report the content build id dev and always match, so editor and PIE sessions are never blocked. In release and profile builds that escape is compiled out, and a client that sends no build id is refused.

Lobby and runs

A hosted session is either in the Lobby (the hub between runs: ready up, swap gear, take new players) or InRun ENetSessionPhase. The host moves it and every client follows.

CallSideWhat it does
SetLocalReady(ready)AnySets this player's ready flag. The host echoes it to everyone.
IsPlayerReady(id), AreAllPlayersReady()AnyRead the flags.
ServerStartRun(force)HostMoves to InRun. Refuses while anyone is not ready, unless forced.
ServerReturnToLobby()HostMoves back to Lobby and clears every ready flag.
SetOnPhaseChanged(fn)AnyObserves phase changes.

With lateJoinPolicy = LobbyOnly, a new player is refused with RunInProgress during a run, while a dropped crew member can still rejoin their held slot.

From Visual Scripting or UI, MNetSessionSubsystem MNetSessionSubsystem wraps the lobby: SetReady, IsLocalReady, AreAllPlayersReady, StartRun, ReturnToLobby, GetPhase, the roster by index (GetPlayerCount, GetPlayerIdAt, GetPlayerNameAt, IsPlayerReadyAt, IsPlayerHostAt), GetLastExitReason and LeaveSession. Every call is a safe no-op outside a session.

Players

Every connection has an FNetPlayer with a player id, peer id, platform id, pawn entity and network id, display name, ready flag and flags such as isHost and isLocal. Read the roster with GetPlayers, FindPlayerById, FindPlayerByPeer and GetLocalPlayer. SetOnPlayerJoined and SetOnPlayerLeft fire on every machine. For a scoreboard or name tags on clients, read the replicated player state records instead of the roster.

SetLocalPlayerState replicates a packed FNetPlayerState word for the local pawn: an animation state, a normalized speed, health, and flags such as crouched, sprinting, downed or dead.

Kick and ban

On the host, KickPlayer(playerId, reason) removes a player immediately and tells them why. BanPlayer also refuses that player's platform id at the next join for the rest of the hosted session; BanPlatformId, UnbanPlatformId and GetBannedPlatformIds manage the list. A player with no platform id (LAN, no online service) can only be kicked. Keeping bans across sessions is the game's job.

Rejoin after a drop

A dropped link does not end a player's run straight away. The host holds the slot, the pawn and its network ids for net.rejoin_grace_seconds (60 by default). Other clients see the player as reconnecting (isInactive on the player state) rather than gone.

  1. The host issues a token
    On the first join, the host sends a 64-bit rejoin token in the welcome message.
  2. The link drops
    The host keeps the player record, pawn and ids. The slot still counts against maxPlayers.
  3. The client rejoins
    The client retries on its own autoRejoinAttempts times, autoRejoinDelaySeconds apart. With autoRejoinAttempts = 0, check IsRejoinPending() and call RejoinSession(world) yourself.
  4. The host re-binds
    The host gives the returning peer the same player id and pawn, moves ownership to the new peer, and resyncs the world. If the window runs out first, the player is released through the normal leave path.

If every attempt fails, the client gives the host up as lost (HostLost) and returns to the menu.

Map travel

Map changes are hard travel: everyone reloads the new scene. ServerBeginTravel(scenePath) sends the travel message to every client and holds new joins. Each client reloads, rebinds with CompleteWorldSwap and acknowledges; the host then resyncs it and respawns its pawn. A client that never acknowledges is dropped after travelAckTimeoutSeconds.

Warning

Clients only accept a relative content path for travel. Absolute paths, drive letters, UNC paths and .. segments are refused (IsSafeTravelScenePath), so a hostile host cannot point a client outside the content tree.

Run a co-op session from the command line

The standalone game reads session flags at startup. The maximum player count comes from the project's platform.defaultMaxPlayers (4 by default), and a Steam lobby is created when platform.steamEnabled is on.

FlagEffect
--host-sessionHost a listen-server session
--connect <host>[:<port>][#<key>]Join an address through the session layer. Port defaults to 7777.
--join-key <key>The host's join key, when not given in --connect
--join-steam <SteamID64>Join a Steam host over Steam P2P
--player-name <name>Display name
--port <n>ENet port for hosting
PowerShell
MowoGame.exe --project=MyGame.mproject --host-session --player-name=Alice
MowoGame.exe --project=MyGame.mproject --connect=192.168.1.20:7777#KEY --player-name=Bob

Replace KEY with the key the host logs and shows in its lobby.

Test multiplayer in the editor

Play As Client in the Play dropdown starts a real networked session on your machine, with a choice of client count, net mode (dedicated server or the viewport as listen server) and client windows. The Network Debug panel inspects it. Both are described in Play in Editor.

Simulate a bad network

Loopback has no loss and almost no latency, so it never exercises interpolation, acknowledgements or reconciliation. Five cvars inject bad conditions on both ENet and Steam transports, and they take effect immediately:

CvarDefaultMeaning
net.sim.loss0Percent of frames dropped
net.sim.latency0Milliseconds of one-way delay
net.sim.jitter0Milliseconds of random delay on top
net.sim.dup0Percent of frames delivered twice
net.sim.reorder0Percent of frames held back so a later frame overtakes them
PowerShell
MowoGame.exe --cvar=net.sim.latency=90 --cvar=net.sim.jitter=25 --cvar=net.sim.loss=2

The Bandwidth tab of the Network Debug panel has a slider for each value and live counters.

Engine sources

This page describes behavior implemented in these files of the engine repository, checked against commit 7f8f31f8d.

  • Engine/Source/Runtime/Networking/Public/Networking/Session/FNetSession.h
  • Engine/Source/Runtime/Networking/Public/Networking/Session/NetSessionTypes.h
  • Engine/Source/Runtime/Networking/Public/Networking/Subsystems/MNetSessionSubsystem.h
  • Engine/Source/Runtime/Project/Public/Project/Project.h

Page feedback

Was this page helpful?