This page is a work in progress and could be pending updates.

Script Execution Control

Overview

There are two main Attributes for controlling the relative script order in which Fusion executes SimulationBehaviour and NetworkBehaviour components:

  • [OrderBefore]
  • [OrderAfter]

These affect nearly all Fusion callbacks, such as FixedUpdateNetwork() and Render().

[OrderBefore(typeof(MyOtherSimulationBehaviour)]
[OrderAfter(typeof(NetworkTransform), typeof(MyOtherNetworkBehaviour))]
public class MySimulationBehaviour : SimulationBehaviour {

}

Back To Top

Sorting Process

During recompiles and on game startup, All SimulationBehaviours are found in the assemblies and are sorted alphabetically with the exception of NetworkPhysicsSimulation3D and NetworkPhysicsSimulation2D.

First each SimulationBehaviour is then checked for [OrderBefore] or [OrderAfter] attributes; if neither exist on the class, then parent classes will be searched recursively and the attributes of the closest parent with either of these attributes will be used. Then all SimulationBehaviours are then sorted to generate a deterministic order which satisfies all OrderBefore and OrderAfter attributes.

N.B.: Any number of [OrderBefore] and [OrderAfter] types can be specified. If they create a conflict that cannot be resolved, the Debug Log will show an error indicating which scripts are in conflict.

NetworkPhysicsSimulation3D and NetworkPhysicsSimulation2D are initially sorted to be after all other alphabetized SimulationBehaviours. To execute scripts after either of these two, they will have to explicit be instructed to do so using the [OrderAfter] attribute.

[OrderAfter(typeof(NetworkPhysicsSimulation3D)]

Back To Top

Inheritance

If a derived script has ordering attribute of its own, it will use the parent's value by default. However, if the child script defines an ordering of its own, then this one will used for its own execution order.

N.B.: Ordering attributes on parent and child scripts therefore are NOT additive.

Back To Top

Simulation Inclusion

The [SimulationBehaviour] attribute can be used to restrict execution of FixedUpdateNetwork() to:

  • only specific stages (Resimulation or Forward); and / or,
  • specific peer modes (Server / Host / Client).
[SimulationBehaviour(
  Stages = SimulationStages.Forward, 
  Modes  = SimulationModes.Server | SimulationModes.Host
)]

Back To Top

Fusion Script Execution Inspector

The Fusion Script Order window can be opened from the menu Fusion > Windows > Script Execution Inspector. This will show in which order and in simulation stages the various scripts will be executed.

N.B.: Script execution is controlled by these attributes:

  • [SimulationBehaviour]
  • [OrderBefore]
  • [OrderAfter]

The Fusion Script Execution Inspector window is only for visualizing the results of these attributes. Attributes must be altered in scripts to make changes.

To Document Top