This document is about: FUSION 2
SWITCH TO

Photon Connection Lost & Quick Reconnect

Feature Overview

Starting with Fusion 2.0.5, a new feature has been introduced to handle Connection Lost cases with the Photon Cloud more gracefully, automatically re-joining sessions. This feature enables better handling of network disconnections, giving developers more control over how their applications respond to connection issues related to the Photon Cloud. By default, the peer will attempt to reconnect to the Photon Cloud up to five times. If all five attempts fail, the peer will either disconnect or move to another session, depending on the configuration (see below for more information).

As an extension of this behavior, starting with Fusion 2.1, servers will also be able to move the session and clients into another room if a quick re-join isn't possible. This enhances the overall robustness of the Fusion Server, ensuring it remains operational even in severe cases.

This feature applies only to Client/Server Modes — Host, Server, and Client. Shared Mode is not supported.

API

Overview

Along with the internal behavior of the automatic reconnection, a new callback, NetworkRunner.CloudConnectionLost, was also introduced. This callback is invoked every time the peer attempts to automatically reconnect to the same Game Session and notify the developer, along with providing an opportunity to implement custom behavior based on the connection status.

C#

NetworkRunner.CloudConnectionLost += (NetworkRunner runner, ShutdownReason reason, bool reconnecting) => { ... };
  • runner: Reference to the NetworkRunner instance.
  • reason: The ShutdownReason, indicating why the connection was lost.
  • reconnecting: A boolean flag indicating if the peer is trying to re-join a session.

Available on Fusion 2.1 onwards, it is also possible to set which behavior will be active via the NetworkRunner.CloudConnectionLostCurrentMode field, which can be set to:

  • CloudConnectionLostMode.Disabled: to completely disable the feature.
  • CloudConnectionLostMode.QuickRejoin: which enables just the quick re-join stage.
  • CloudConnectionLostMode.MoveSessionToNewRoom: which, along with the quick re-join, also enables the Server to move into another Room.

Triggering Conditions

The feature will fire in two main scenarios:

  1. Photon Cloud Timeout: When a disconnect occurs due to a Photon Cloud Timeout, the callback will receive a ShutdownReason.PhotonCloudTimeout.
  2. Session Not Found: If the session was closed/terminated before a re-join attempt could succeed, the callback will receive a ShutdownReason.GameNotFound.

Client Behavior

When the feature is enabled, the peer will not shut down automatically upon losing connection to the Photon Cloud and will attempt to automatically re-join the session.

The callback can be implemented and used to notify the player that a reconnection process is in place and the game will continue shortly, for example.

Server Behavior

Only Quick Re-join is Enabled

This is the only available option for Fusion 2.0.5+.

If the server loses connection to the Photon Cloud and cannot rejoin after the reconnection attempts (same behavior as the Client described above):

  • The Fusion Plugin will automatically set the Session as Invisible and Closed.
  • No new clients will be able to join the session.
  • Existing directly connected clients will stay connected and continue playing normally.

This guarantees that the Server keeps running and the Game Session stays active for already connected players, even if it loses connection to the Photon Cloud.

Move Session to a new Room

Available only on Fusion 2.1.0+ and enabled by default.

If the server loses connection to the Photon Cloud it attempts Quick Re-join, as above.

If that also fails then it will move the session to a new room:

  • It will generate a new Session ID (based on the current Session ID or by invoking the StartGameArgs.SessionNameGenerator) and append [bpk-<6 long random digits>] to prevent clashes with other Sessions. Keep in mind, the entire Session ID will be a maximum of 200 characters and will be automatically trimmed if it exceeds this limit.
  • Create a new Session with the generated ID and set it as Invisible.
  • Notify all directly connected clients to connect to another Session.
  • Wait up to 10 seconds for clients to reconnect.
  • Make the Session Visible again so other clients can find and join it.

The Game Session continues normally during the transfer and the room can be matchmade against after the transfer.

Example

Here's a basic implementation of the Cloud Connection Lost feature:

C#

public class NetworkRunnerCloudConnectionLost : MonoBehaviour
{
    private void Start()
    {
        // Valid only for 2.1.0+
        // Set Cloud Connection Lost Mode.
        // CloudConnectionLostMode.MoveSessionToNewRoom is already the default
        NetworkRunner.CloudConnectionLostCurrentMode = NetworkRunner.CloudConnectionLostMode.MoveSessionToNewRoom;

        // Valid for 2.0.5+ and 2.1.0+
        NetworkRunner.CloudConnectionLost += OnCloudConnectionLost;
    }

    private void OnCloudConnectionLost(NetworkRunner runner, ShutdownReason reason, bool reconnecting)
    {
        if (reconnecting)
        {
            // e.g. notify player the game is reconnecting
            Debug.Log($"Cloud Connection Lost: {reason}, reconnecting...");
            // then, wait for automatic reconnection to complete
            StartCoroutine(WaitForReconnection(runner));
        }
        else
        {
            Debug.Log($"Cloud Connection Lost: {reason}.");
            // Handle scenarios where reconnection is not possible
            // e.g. notify the user, fully shutdown the NetworkRunner, etc.
        }
    }

    private IEnumerator WaitForReconnection(NetworkRunner runner)
    {
        // e.g. notify player the game has reconnected
        yield return new WaitUntil(() => runner.IsInSession);
        Debug.Log("Reconnected to the Cloud!");
    }
}

This example demonstrates how to register the callback, handle different scenarios, and wait for a successful reconnection.

Back to top