Handle host migration
Host migration applies only to persistent reserved rooms. When the active host disconnects, the relay selects the client with the earliest join order and gives it 10 seconds to acknowledge, reconnect, and claim the host role.
Fish-Networking
Section titled “Fish-Networking”The Fish-Networking transport performs the transition automatically:
- The transport receives
HostPromotedand acknowledges the claim. - The relay disconnects the promoted client.
- The transport waits until both local client and server states are stopped.
- It starts the server using the pending claim token.
- After the server claims the room, it starts the local client.
Use OnRelayHostAvailabilityChanged to pause host-dependent game actions while migration is in progress:
private void OnEnable(){ transport.OnRelayHostAvailabilityChanged += HandleHostAvailability;}
private void OnDisable(){ transport.OnRelayHostAvailabilityChanged -= HandleHostAvailability;}
private void HandleHostAvailability(bool available){ matchmakingOverlay.SetActive(!available);}Netcode for GameObjects
Section titled “Netcode for GameObjects”NGO owns its NetworkManager lifecycle, so the NGO transport exposes the promotion and waits for game code to switch roles.
- Subscribe to
OnHostPromotionReceivedbefore starting the client. - When invoked, call
NetworkManager.Shutdown(). - Wait until
NetworkManager.ShutdownInProgressis false and neither client nor server is listening. - Call
NetworkManager.StartHost()orStartServer(). - The transport uses its pending claim automatically and clears it after
RoomCreatedarrives.
using System.Collections;using BlitzRelay.Ngo;using Unity.Netcode;using UnityEngine;
public sealed class NgoHostMigration : MonoBehaviour{ [SerializeField] private NetworkManager networkManager; [SerializeField] private BlitzRelayTransport transport;
private void OnEnable() { transport.OnHostPromotionReceived += HandlePromotion; }
private void OnDisable() { transport.OnHostPromotionReceived -= HandlePromotion; }
private void HandlePromotion(HostPromotion promotion) { StartCoroutine(BecomingHost()); }
private IEnumerator BecomingHost() { networkManager.Shutdown();
while (networkManager.ShutdownInProgress || networkManager.IsClient || networkManager.IsServer) { yield return null; }
networkManager.StartHost(); }}Availability events
Section titled “Availability events”Clients receive HostUnavailable while a persistent room has no active host and HostAvailable after a claim succeeds. These events describe relay availability; they do not migrate your game state. Your networking framework still needs its own authoritative state-transfer strategy.