KSP API
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties
Public Types | Public Member Functions | Public Attributes | Properties | List of all members
PartModule Class Reference

Extending PartModule lets you add new functionality to parts. The main class of many plugins will be a subclass of PartModule. See this forum thread for the official instructions on using PartModule: More...

Inheritance diagram for PartModule:
KerbalEVA ModuleAsteroid ModuleEngines ModuleScienceExperiment

Public Types

enum  StartState {
  StartState.None = 0, StartState.Editor = 1, StartState.PreLaunch = 2, StartState.Landed = 4,
  StartState.Docked = 8, StartState.Flying = 16, StartState.Splashed = 32, StartState.SubOrbital = 64,
  StartState.Orbital = 128
}
 A StartState is passed on OnStart in order to provide the PartModule with some information about where it is starting up. More...
 

Public Member Functions

 PartModule ()
 
virtual string GetInfo ()
 The return value of this function appears in the part's description in the editor. More...
 
void Load (ConfigNode node)
 
virtual void OnActive ()
 This function is called once when the part gets activated. More...
 
virtual void OnAwake ()
 This function gets called only once, during the KSP loading screen. See the Unity documentation on Awake for more information. More...
 
virtual void OnFixedUpdate ()
 This function gets called once every Unity FixedUpdate cycle (once per physics frame) once the part has been activated. If you want to be called even if the part has not been activated, define a function called void FixedUpdate() instead of overriding OnFixedUpdate More...
 
virtual void OnInactive ()
 When does this get called? More...
 
virtual void OnLoad (ConfigNode node)
 This function is called to initialize the part. The ConfigNode contains the parameters of the module as specified in the part.cfg file, or as you last saved them in OnSave. More...
 
virtual void OnSave (ConfigNode node)
 This function is called when the game is saved to let the part save persistent data. Add any data you want to persist to the ConfigNode. The ConfigNode will then be saved as part of persistent.sfs. When the game is resumed, you can then read this data back out in OnLoad. More...
 
virtual void OnStart (PartModule.StartState state)
 Called when the flight starts, or when the part is created in the editor. OnStart will be called before OnUpdate or OnFixedUpdate are ever called. More...
 
virtual void OnUpdate ()
 Called once per Unity Update cycle once the part has been activated. If you want to be called even if the part has not been activated, define a function called void Update() instead of overriding OnFixedUpdate. More...
 
void Save (ConfigNode node)
 

Public Attributes

bool isEnabled
 
string moduleName
 
ProtoPartModuleSnapshot snapshot
 

Properties

BaseActionList Actions [get]
 A list of KSPActions which can be added to action groups. More...
 
int ClassID [get]
 A hash of ClassName? More...
 
string ClassName [get]
 In any subclass of PartModule, ClassName will be the name of the subclass. It gets set by the PartModule loading process. More...
 
BaseEventList Events [get]
 A list of KSPEvents, which can be triggered by code or by the user through the part's right-click menu. More...
 
BaseFieldList Fields [get]
 A list of the KSPFields which the module loads from the part.cfg file. More...
 
string GUIName [get]
 
Part part [get, set]
 The Part to which this PartModule is attached. Use this to reference the part from your module code. More...
 
Vessel vessel [get]
 The Vessel of the Part to which this PartModule is attached. More...
 

Detailed Description

Extending PartModule lets you add new functionality to parts. The main class of many plugins will be a subclass of PartModule. See this forum thread for the official instructions on using PartModule:

http://forum.kerbalspaceprogram.com/showthread.php/10296-0-15-code-update-PartModule-KSPField-KSPEvent-ConfigNode-and-PartResource

Member Enumeration Documentation

A StartState is passed on OnStart in order to provide the PartModule with some information about where it is starting up.

Enumerator
None 
Editor 
PreLaunch 
Landed 
Docked 
Flying 
Splashed 
SubOrbital 
Orbital 

Constructor & Destructor Documentation

PartModule.PartModule ( )

Member Function Documentation

virtual string PartModule.GetInfo ( )
virtual

The return value of this function appears in the part's description in the editor.

Returns
Editor info for the part

Reimplemented in ModuleEngines.

void PartModule.Load ( ConfigNode  node)
virtual void PartModule.OnActive ( )
virtual

This function is called once when the part gets activated.

Reimplemented in ModuleEngines, and ModuleScienceExperiment.

virtual void PartModule.OnAwake ( )
virtual

This function gets called only once, during the KSP loading screen. See the Unity documentation on Awake for more information.

Reimplemented in ModuleEngines, and ModuleScienceExperiment.

virtual void PartModule.OnFixedUpdate ( )
virtual

This function gets called once every Unity FixedUpdate cycle (once per physics frame) once the part has been activated. If you want to be called even if the part has not been activated, define a function called void FixedUpdate() instead of overriding OnFixedUpdate

See the Unity documentation on FixedUpdate for more information. You can get the time between FixedUpdates from TimeWarp.fixedDeltaTime. Do any physics stuff in OnFixedUpdate, not OnUpdate.

virtual void PartModule.OnInactive ( )
virtual

When does this get called?

virtual void PartModule.OnLoad ( ConfigNode  node)
virtual

This function is called to initialize the part. The ConfigNode contains the parameters of the module as specified in the part.cfg file, or as you last saved them in OnSave.

Parameters
nodeA ConfigNode containing the module's parameters from part.cfg or persistent.sfs

Reimplemented in ModuleEngines, ModuleScienceExperiment, and KerbalEVA.

virtual void PartModule.OnSave ( ConfigNode  node)
virtual

This function is called when the game is saved to let the part save persistent data. Add any data you want to persist to the ConfigNode. The ConfigNode will then be saved as part of persistent.sfs. When the game is resumed, you can then read this data back out in OnLoad.

Parameters
node

Reimplemented in ModuleEngines, ModuleScienceExperiment, and KerbalEVA.

virtual void PartModule.OnStart ( PartModule.StartState  state)
virtual

Called when the flight starts, or when the part is created in the editor. OnStart will be called before OnUpdate or OnFixedUpdate are ever called.

Parameters
stateSome information about what situation the vessel is starting in.

Reimplemented in ModuleEngines, ModuleScienceExperiment, KerbalEVA, and ModuleAsteroid.

virtual void PartModule.OnUpdate ( )
virtual

Called once per Unity Update cycle once the part has been activated. If you want to be called even if the part has not been activated, define a function called void Update() instead of overriding OnFixedUpdate.

See the Unity documentation on Update for more information. Poll for user input in OnUpdate, not OnFixedUpdate.

void PartModule.Save ( ConfigNode  node)

Member Data Documentation

bool PartModule.isEnabled
string PartModule.moduleName
ProtoPartModuleSnapshot PartModule.snapshot

Property Documentation

BaseActionList PartModule.Actions
get

A list of KSPActions which can be added to action groups.

int PartModule.ClassID
get

A hash of ClassName?

string PartModule.ClassName
get

In any subclass of PartModule, ClassName will be the name of the subclass. It gets set by the PartModule loading process.

BaseEventList PartModule.Events
get

A list of KSPEvents, which can be triggered by code or by the user through the part's right-click menu.

BaseFieldList PartModule.Fields
get

A list of the KSPFields which the module loads from the part.cfg file.

string PartModule.GUIName
get
Part PartModule.part
getset

The Part to which this PartModule is attached. Use this to reference the part from your module code.

Vessel PartModule.vessel
get

The Vessel of the Part to which this PartModule is attached.


The documentation for this class was generated from the following file: