Fixed Update Network
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
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.
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.
The following simulation properties can be used on
FUN() to know in which state the current simulating tick is (e.g
- IsResimulation: Use inside of
FixedUpdateNetworkto determine if the tick currently being simulated has previously been simulated locally.
- IsForward: Use inside of
FixedUpdateNetworkto determine if the tick currently being simulated has NOT previously been simulated locally.
- IsLastTick: Use in conjunction with
IsForwardinside 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
IsForwardinside of FixedUpdateNetwork to determine if the current tick being simulated is the first tick of the resimulation or forward phase of the simulation loop.
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.
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
[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 (
NetworkPhysics3D). For more information on script execution control please visit the page of the same name.