Script execution order

Scripts are not executed in a random fashion: script type, script location and script settings can influence when (in relation to others) a script is being executed. A simple rule to remember is: the more important or persistent a script is, the later it will be called/executed.

Execution order is first based on script type. We have following order, from first executed to last executed:

  • child scripts are called
  • customization scripts are called
  • add-on scripts are called
  • the sandbox script is called
  • Because child scripts are simulation scripts, they will only run as long as the simulation is running (i.e. they are not persistent). This is not the case with customization scripts, add-ons and the sandbox script, which run also after a simulation stop. Additionally, add-ons and the sandbox script also continue to run when switching to a different scene. Above sequence makes sense since important scripts can be designed to rely and operate on data produced by less important scripts.

    As an example, the callback sysCall_sensing will be called in following sequence: first in child scripts, then in customization scripts, in add-ons, and finally in the sandbox script.

    Within a script type, the execution order is a function of a script's position in the scene hierarchy, and its following 2 script settings:

  • Execution priority: specifies the execution priority for a script. The execution priority relates only to same-type scripts, and only to scripts that are siblings in the scene hierarchy.
  • [Script execution order based on execution priority setting]

  • Tree traveral: specifies when a script is executed, in relation to the scripts attached further down in the scene hierarchy (its descendants scripts). With reverse, the descendant scripts are first executed, with forward, the descendant scripts are executed last. Same as parent uses the same tree traversal as the first ancestor script. The tree traversal relates only to same-type scripts. Default is reverse.
  • [Script execution order based on tree traversal setting]

    Following diagram illustrates a concret example scene:

    [Example scene and child script execution order]