KSP Core Concepts - KSPModdingLibs/KSPModdingWiki GitHub Wiki

KSPAddon

This is an attribute that you can place on a class that inherits from MonoBehaviour, which will mark that class as an addon. KSP will instantiate an object with this component on certain scene transitions according to the parameters you use for the Startup and once values.

GameEvents

A collection of static events where you can register a delegate to be called when various things happen. IMPORTANT: If you add an event handler, you must remove it when your object is destroyed (generally use OnDestroy for this) or else you will cause a memory leak. Do not use lambda expressions as event handlers because you cannot easily remove them.

Vessel

Represents a distinct vessel in flight. Note that Kerbals on EVA, flags, and asteroids are all Vessels. There is only one active vessel, which is the one that the player is controlling. This can be accessed via FlightGlobals.activeVessel - but be warned that it may be null in some cases.

When two vessels dock, they become one vessel. Any time they separate - whether undocking, decoupling, a part breaking - then they become multiple vessels again.

A vessel can be loaded or unloaded - vessels that are unloaded do not have Parts instantiated. Generally, vessels that are within a certain range of the active vessel will be loaded. Further, a loaded vessel can be packed or unpacked - packed vessels do not simulate physics. All vessels are packed during timewarp, and a non-active vessel will not be unpacked until it gets rather close to the active one.

Part

Vessels are primarily a collection of Parts, which in turn have a collection of PartModules. Parts are arranged in a tree - each Vessel has one root Part, and each Part has one parent and potentially many children.

Parts are created by cloning a prefab from the GameDatabase. The prefab is accessible via Part.partInfo.partPrefab. The prefab is set up via a top-level PART node in a cfg file.

PartModule

Most of the behavior of Parts is provided by PartModules. These are instantiated as components on the Part gameobject. The PART node in the cfg file specifies which modules are in the part.

VesselModule

Classes that inherit from VesselModule will be added to every Vessel in the world. This is a good place to store information per-vessel and especially for unloaded vessels, as well as persisting per-vessel data to the save file. Please pay careful attention to the Activation and ShouldBeActive methods so that you do not spend time updating unloaded vessels, flags, debris, etc. if you don't need to.

ScenarioModule

ConfigNode

ConfigNodes are created from .cfg text files in GameData, and are the core way that objects are configured for the game. A ConfigNode has a name (which is usually used as a type and should not be confused with a name field), a list of child nodes, and a list of key/value pairs.

ModuleManager is a tool for using .cfg files to modify other .cfg files, and is invaluable in the modding ecosystem so that different mods can alter the same parts without needing to actually overwrite each other's files.

Scene

InternalModel

InternalProp

InternalModule

CelestialBody

GameDatabase

KSPField

KSPEvent