Execution Order
Overview
The execution loops for Fusion can be broken down into three main loops:
- the Resimulation Loop;
- the Forward Loop; and,
- the Render Loop.
The following sections will present these three loops and the order in which scripts & callbacks are called in them.
- INT: Callbacks marked as- INTare used internally by Fusion and are only included for
- CB: Callbacks marked as- CBare available to the user and can be hooked into by implementing the associated interface in scripts inheriting from- NetworkBehaviourand- SimulationBehaviour.
Download Complete Graphic
The complete execution order graphic can be downloaded HERE.
Fusion Initialization
When Fusion is first started, the NetworkRunner looks for all components implementing INetworkRunnerCallbacks on the same object as the Runner. If none can be detected in Awake() another attempt will be done during the Fusion Update Loop, or -in the rare case the runner is immediately destroyed- during the Shutdown Handling to exit gracefully.
Scripts implementing INetworkRunnerCallbacks and not located on the same object or hierarchie level as the NetworkRunner, need to register themselves at a later point with the NetworkRunner by calling NetworkRunner.AddCallbacks() after the Runner has been successfully initialized.
 
    Fusion Update Loop
The core of the Fusion simulation is handled by the Resimulation and Forward loops. Prior to their execution:
- Unity's own FixedUpdate() methods are executed; and,
- The local Physics simulation is run if PhysicsMode.Nonewas selected.
 
    After these steps, the Fusion Update Loop starts. The Fusion Update Loop is made of the following execution steps:
- the callbacks registered with the NetworkRunnerare executed.
- the NetworkObjectspawn queue is processed. This takens place ONLY IF theSceneManageris busy ANDSceneLoadSpawnMode.Queuedis selected in theNetworkProjectConfig > Object Settings
- the Resimulation Loop runs.
- the Forward Loop runs.
- OnChangedcallbacks are called after both loops have finished executing.
- the Interest Management is updated.
- the Shutdown Handling is triggered if NetworkRunner.Shutdown()was called inFixedUpdateNetwork()during the Resimulation or Forward loop.
 
    Update Loop Start
 
    Resimulation Loop
ServerMode and HostModeThe Resimulation Loop reconciliates the local state with the latest state received from the Server or Host. It does so by resetting the network state to the most recent state received and resimulating all the ticks from the most recent server tick included in the validated state up until the current predicted local tick.
 
    Forward Loop
SharedModeIn HostMode & ServerMode
The Forward Loop simulates the next predicted ticks after the Resimulation Loop finished reconciling the current known [Networked] state.
In SharedMode
The Forward Loop is the only loop running the simulation; this covers the simulation for objects over which the local simulation has State Authority and the apply the state received for proxy objects.
 
    Update Loop End
 
    Render Loop
The Render Loop is used for all things unrelated to gameplay or the gamestate. Its main purpose is to provide an entry for interpolation and visual feedback logic such as VFX and animation.
- Before Render(), all of Unity'sUpdate()methods are executed.
- After Render(), all of Unity'sLateUpdatemethods are executed.
The Shutdown Handling is triggered if NetworkRunner.Shutdown() was called during the Render Loop.
