Script execution precedence

Script callback functions are not executed in a random order: script location and type have an influence on when (in relation to others) a script is executed or called:

Execution precedence is first and foremost based on location: a script object has always higher priority than its ancestory (e.g. parent, grand-parent, etc.) and thus will be called before. In case of two sibling script objects, precedence is given by the order they appear in the scene hierarchy, unless they have a different priority flag, in which case that flag decides the precedence. See the script dialog for details.

Execution precedence is next decided by the script type, from first to last executed: simulation script, customization script, add-on, and finally the sandbox.

[Example scene with script execution precedence]

A simple rule to remember is: the more important or persistent a script is, the later it will be called. There are exceptions to this, depending on the callback type: e.g. the contact- and the dynamics callback are executed in reverse order (within a given script type). Additionally, when the caller expects a return value, the call chain is interrupted as soon as the first return value is received.