This page is a work in progress and could be pending updates.
fusion | v1 switch to V2  

Network Callbacks

Introduction

Fusion provides a variety of callbacks to hook on into, those callbacks are useful to get access to specific parts of the simulation and receive important events.

INetworkRunnerCallbacks

The NetworkRunner allows the application to hook into important network related events by implementing the INetworkRunnerCallbacks interface and registering the script with the runner by calling NetworkRunner.AddCallbacks().

Note: NetworkRunner will auto register all components with INetworkRunnerCallback on the same GameObject AND the same hierarchical level. All other instances of INetworkRunnerCallbacks will need to use NetworkRunner.AddCallbacks().

Method Return Additional Info
OnPlayerJoined NetworkRunner runner: The local player NetworkRunner reference.
PlayerRef player: The PlayerRef of the joined player.
Callback from a NetworkRunner when a new player has joined. Usually used for spawning an avatar for the new player.
OnPlayerLeft NetworkRunner runner: The local player NetworkRunner reference.
PlayerRef player: The PlayerRef of the leaving player.
Callback from a NetworkRunner when a player has disconnected. Usually used for despawning the player avatar.
OnInput NetworkRunner runner: The local player NetworkRunner reference.
NetworkInput input: The NetworkInput struct used for sending the polled inputs.
Callback from NetworkRunner that polls for user inputs. The NetworkInput that is supplied expects: input.Set(new CustomINetworkInput() { /* your values *‍/ });
OnInputMissing NetworkRunner runner: The local player NetworkRunner reference.
NetworkInput input: The NetworkInput struct used for sending the polled inputs.
Callback called on the host when it cannot get a input from a specific player on that particular tick. The provided NetworkInput can be used to generate substitute inputs.
OnShutdown NetworkRunner runner: The local player NetworkRunner reference.
ShutdownReason shutdownReason: The reason for the shutdown on the format of an enum.
Called when the local runner is shutdown.
OnConnectedToServer NetworkRunner runner: The local player NetworkRunner reference. Callback when NetworkRunner successfully connects to a server or host.
OnDisconnectedFromServer NetworkRunner runner: The local player NetworkRunner reference. Callback when NetworkRunner disconnects from a server or host.
OnConnectRequest NetworkRunner runner: The local player NetworkRunner reference.
NetworkRunnerCallbackArgs.ConnectRequest request: Data holder of a Connection Request from a remote client.
byte[] token: A custom connection token that the client provide.
Callback when NetworkRunner receives a Connection Request from a Remote Client.
OnConnectFailed NetworkRunner runner: The local player NetworkRunner reference.
NetAddress remoteAddress: Represents a Network Address, which includes a IP and Port. This can contains either a IPv4 or a IPv6 address.
NetConnectFailedReason reason: The reason for the fail on connect on the format of an enum.
Callback when NetworkRunner fails to connect to a server or host.
OnUserSimulationMessage NetworkRunner runner: The local player NetworkRunner reference.
SimulationMessagePtr message: A pointer to the simulation message received
This callback is invoked when a manually dispatched simulation message is received from a remote peer.
OnSessionListUpdated NetworkRunner runner: The local player NetworkRunner reference.
List< SessionInfo > sessionList: The list of SessionInfo received.
This callback is invoked when a new List of Sessions is received from Photon Cloud.
OnCustomAuthenticationResponse NetworkRunner runner: The local player NetworkRunner reference.
Dictionary< string, object > data: Custom authentication reply values.
Callback is invoked when the Authentication procedure returns a response from the Authentication Server.
OnHostMigration NetworkRunner runner: The local player NetworkRunner reference.
HostMigrationToken hostMigrationToken: Transitory Holder with all necessary information to restart the Fusion Runner after the Host Migration has completed.
Callback is invoked when the Host Migration process has started.
OnReliableDataReceived NetworkRunner runner: The local player NetworkRunner reference.
PlayerRef player: The player that sent the data.
ArraySegment< byte > data: The data received.
Called when a reliable data was received. It can be used for transfer more robust data, like a texture for instance. It should be used with caution.
OnSceneLoadDone NetworkRunner runner: The local player NetworkRunner reference. Called by NetworkSceneManagerBase when the scene loading process is finished. If implementing a custom one to provide on StartGameArgs.SceneManager, it will be needed to call this callback manually.
OnSceneLoadStart NetworkRunner runner: The local player NetworkRunner reference. Called by NetworkSceneManagerBase when the scene loading process is started. If implementing a custom one to provide on StartGameArgs.SceneManager, it will be needed to call this callback manually.

Execution Order Callbacks

There is plenty of specific callbacks for each part of the simulation, they are all showcased on the Execution Order Page, the following are a few picks that worth mentioning here.

IBeforeAllTicks/IAfterAllTicks

Those interfaces are used to get access to BeforeAllTicks(bool resimulation, int tickCount) and AfterAllTicks(bool resimulation, int tickCount). Those are called before the resimulation loop (when applicable), and also before the forward simulation loop. Only called on Updates where resimulation or forward ticks are processed.

The resimulation boolean will be true when executing before the resimulation and false when called before the forward ticks. The tickCount will provide how many ticks are going to be processed.

IBeforeTick/IAfterTick

Similar to the above, but will run for each tick.

To Document Top