Skip to main content

About NetworkUpdateLoop

Often there is a need to update netcode systems like RPC queue, transport IO, and others outside the standard MonoBehaviour event cycle.

The Network Update Loop infrastructure utilizes Unity's low-level Player Loop API allowing for registering INetworkUpdateSystems with NetworkUpdate() methods to be executed at specific NetworkUpdateStages which may be either before or after MonoBehaviour-driven game logic execution.

Typically you will interact with NetworkUpdateLoop for registration and INetworkUpdateSystem for implementation. Systems such as network tick and future features (such as network variable snapshotting) will rely on this pipeline.

Registration

NetworkUpdateLoop exposes four methods for registration:

MethodRegisters
void RegisterNetworkUpdate(INetworkUpdateSystem updateSystem, NetworkUpdateStage updateStage)Registers an INetworkUpdateSystem to be executed on the specified NetworkUpdateStage
void RegisterAllNetworkUpdates(INetworkUpdateSystem updateSystem)Registers an INetworkUpdateSystem to be executed on all NetworkUpdateStages
void UnregisterNetworkUpdate(INetworkUpdateSystem updateSystem, NetworkUpdateStage updateStage)Unregisters an INetworkUpdateSystem from the specified NetworkUpdateStage
void UnregisterAllNetworkUpdates(INetworkUpdateSystem updateSystem)Unregisters an INetworkUpdateSystem from all NetworkUpdateStages

Update Stages

After injection, the player loops follows these stages. The player loop executes the Initialization stage and that invokes NetworkUpdateLoop's RunNetworkInitialization method which iterates over registered INetworkUpdateSystems in m_Initialization_Array and calls INetworkUpdateSystem.NetworkUpdate(UpdateStage) on them.

In all NetworkUpdateStages, it iterates over an array and calls the NetworkUpdate method over INetworkUpdateSystem interface, and the pattern is repeated.

StageMethod
InitializationRunNetworkInitialization
EarlyUpdateRunNetworkEarlyUpdate
ScriptRunDelayedStartupFrame
Other systems
FixedUpdateRunNetworkFixedUpdate
ScriptRunBehaviourFixedUpdate
Other systems
PreUpdateRunNetworkPreUpdate
PhysicsUpdate
Physics2DUpdate
Other systems
UpdateRunNetworkUpdate
ScriptRunBehaviourUpdate
Other systems
PreLateUpdateRunNetworkPreLateUpdate
ScriptRunBehaviourLateUpdate
PostLateUpdatePlayerSendFrameComplete
RunNetworkPostLateUpdate
Other systems

References

See Network Update Loop Reference for process flow diagrams and code.