Execution order of plugins code - KSPModdingLibs/KSPModdingWiki GitHub Wiki

Execution order of the Monobehaviour message methods like Awake(), Start() or Update() is determined by the ExecutionOrder of the Monobehaviour. If undefined, the execution order is 0.

Note that while execution order of same ExecutionOrder Monobehaviour objects is documented as non-deterministic, in practice the messages are usually called by a pre-order depth-first traversal of the scene hierarchy, but this isn't true for all messages and in all situations.

Setting a non-default ExecutionOrder can be done with the DefaultExecutionOrder attribute, for example :

[DefaultExecutionOrder(50)]
public class MyKSPMonobehaviour : Monobehaviour

This can be applied to any class deriving from Monobehaviour, including the various stock classes such as KSPAddon, ScenarioModule, VesselModule or even PartModule.

Alternatively, KSP provide through the TimingManager class static methods allowing to register method delegates at specific points in the execution order (see the TimingStage enum), for the three main gameloop messages : Update, LateUpdate and FixedUpdate.

Using a custom execution order is an advanced use case, and is usually not needed nor recommended unless there is a specific need due to a required interaction with another plugin or stock Monobehaviour.

Here is the ExecutionOrder for every non-default execution order stock Monobehaviour, as of KSP 1.12.5 :

Execution order Monobehaviour TimingStage
-8008 Timing0 ObscenelyEarly
-1100 Versioning
-1000 DatabaseGameObject
-200 GameSettings
-104 Planetarium
-102 VesselPrecalculate
-101 TimingPre Precalc
-100 OrbitDriver
-99 Timing1 Early
-80 CollisionEnhancer
-1 Timing2 Earlyish
0 [default order] Normal
3 EditorLogic
5 KerbalEVA
7 Timing3 FashionablyLate
8 FlightIntegrator
9 TimingFI FlightIntegrator
10 PQSCity2
12 OrbitPhysicsManager
13 Vessel
19 Timing4 Late
20 Krakensbane
21 FloatingOrigin
25 FlightCoMTracker
30 FlightCamera
300 PlanetariumCamera
500 ScaledSpace
540 Sun
550 ScaledCamera
560 TimeOfDayAnimation
600 OrbitRenderer
601 WaypointManager
602 ContractOrbitRenderer
603 CommNetUI
700 PatchedConicRenderer
800 OrbitTargeter
1200 ManeuverGizmo
1250 AerodynamicsFX
1280 FXCamera
1300 ReentryFXParticleTrail
1400 KerbalEVATestInitializer
1900 InternalSpaceOverlay
1900 Mouse
8008 Timing5 BetterLateThanNever