Skip to main content
C++

Custom Adapter

Everything platform specific sits behind UHostMigrationSessionAdapter. Subclass it (or UHostMigrationAdapter_Null for the LAN fallbacks) and pick your class in Project Settings → Plugins → Host Migration → Adapter Class.

An adapter answers three questions:

  1. Is a player still in the session (presence)?
  2. How does a host announce itself so the others can find it?
  3. What is this machine's address?
FunctionPurpose
GetConnectAddress(Candidate)Required. Address for ClientTravel to reach a candidate once it hosts.
GetLocalHostAddress()Address others use to reach this machine while it hosts.
GetMemberPresence(PlayerId)Present / Gone / Unknown. Enables rejoin and skipping candidates who left.
IsCandidateAvailable(Candidate)Election: false skips the candidate. Default: not known to be gone.
PublishHostReady(Epoch, NumPlayers)Announce that this machine hosts. Called when hosting starts and when the player count changes.
ClearHostReady()This machine stopped hosting.
PublishHostLoading(Epoch)This machine is loading the map as the successor for this epoch.
IsCandidateLoading(Candidate, Epoch)True if that candidate published it is loading. Clients then wait up to Max Candidate Load Time.
PublishHeartbeat(Beat)Called every HeartbeatInterval (5 s) while hosting. Write the number to the backend.
GetHeartbeat(PlayerId, OutBeat)Read the number that player wrote. Return false if there is none. A host whose beat has not changed for HeartbeatTimeout (15 s) counts as gone.
GetAnnouncedHosts(OutHosts)Every announcement visible in the backend. Return false if there is no such channel.
FindAnnouncedHost(...)For players not connected yet. Default: highest epoch, then most players. Fills in the host's id, address and epoch.
CanSeeLobby()False when this machine cannot read the backend. Clients then connect to the candidate directly. Default: true.
GetDirectConnectAddresses(Candidate, OutAddresses)Addresses tried when CanSeeLobby() is false. Default: GetConnectAddress.
ScoreCandidate(PlayerState)Host side, lower is better. Default: ping.
BeginWaitingForHost / StopWaitingForHostClient side, while waiting for a candidate.
IsOnline()False fires On Host Connection Lost on the host. Default: true.
GetDebugInfo(OutLines)Extra text for the Adapter line of the debug overlay.
Initialize / DeinitializeLifetime, tied to the subsystem.

If your backend pushes events, call UHostMigrationSubsystem::HandleHostAnnounced when an announcement arrives. When your backend becomes usable after hosting started, call RefreshHostAnnouncement.

The Null adapter exposes Listen Port, Assumed Host Delay, and Take Over Session as class defaults. See LAN fallback settings for defaults and when each applies.

Why not one adapter on top of the Online Subsystem?​

Host migration needs per-member data that every member can write.

  • OSSv1 (IOnlineSubsystem): only the session owner writes session data, and member settings are not implemented by every backend. EOS has them, Steam does not.
  • OSSv2 (UE::Online::ILobbies): has member attributes and member-left events, but in 5.8 only EOS and Null implement Lobbies.

So Steam and EOS each have their own adapter, working on Steam lobbies and EOS lobbies directly.