Fixed Update Network
Overview
FixedUpdateNetwork()
- abbreviated FUN()
- is called when simulating the new state from one tick to the next. FixedUpdateNetwork()
is called at fixed intervals. The time step of these intervals is defined in the NetworkProjectConfig
asset under Simulation > Tick Rate
. The time step can be accessed from any SimulationBehaviour
and NetworkBehaviour
via the Runner.DeltaTime
property, it should be used in any scenario where Unity's Time.deltaTime
would have been used when it comes to simulation logic.
The FUN()
method should contain all the simulation logic to allow the ticks to be correctly re-simulated and guarantee that the state is sync between clients.
Simulation and Resimulation
FixedUpdateNetwork()
can be called multiple times for the same state transition to re-simulate the current predicted state based on updates (ground truth) received from the server. The re-simulation is transparent for [Networked]
properties because Fusion will reset the network state before calling FixedUpdateNetwork()
for re-simulation purposes.
IMPORTANT: Regular local non-networked state variables (e.g. class members) will not be reset and simply consider it an additional forward state progression.
Simulation Tick
The following simulation properties can be used on FUN()
to know in which state the current simulating tick is (e.g Runner.Simulation.IsResimulation
):
- IsResimulation: Use inside of
FixedUpdateNetwork
to determine if the tick currently being simulated has previously been simulated locally. - IsForward: Use inside of
FixedUpdateNetwork
to determine if the tick currently being simulated has NOT previously been simulated locally. - IsLastTick: Use in conjunction with
IsResimulation
/IsForward
inside of FixedUpdateNetwork to determine if the current tick being simulated is the last tick of the resimulation or forward phase of the simulation loop. - IsFirstTick: Use in conjunction with
IsResimulation
/IsForward
inside of FixedUpdateNetwork to determine if the current tick being simulated is the first tick of the resimulation or forward phase of the simulation loop.
Execution Order
FixedUpdateNetwork
lies at the center of both the Resimulation and Forward Loops. FUN is the place where all gameplay logic affecting the [Networked]
state is located and executed.
By default, NetworkBehaviours
and SimulationBehaviours
are arbitrarily ordered. This means the order in which FUN is executed for all of these may vary between simulations participating in the same Game Session. Part of the the FUN Loop is the Network Physics Simulation which runs in the "middle" of it if the PhysicsEngine
is set to either Physics 3D
or Physics 2D
. Thus, by default, certain Behaviours will have their FixedUpdateNetwork
method be executed before or after the Network Physics.
FUN and Physics
It is possible to explicitly order Behaviours before or after certain other types of Behaviours by using the class attributes [OrderedBefore()]
and [OrderedAfter()]
. These attributes can also be used to have Behaviours run before or after the Network Physics by specifying the type of Physics used in this simulation (NetworkPhysics2D
or NetworkPhysics3D
). For more information on Script Execution Control please visit the page of the same name.