Jump to content

Part vs. PartModule?


Recommended Posts

So me being totally new to modding KSP (or games for that matter, although I'm a semi-experienced C++ programmer), I just want to know what the difference is between these two classes are. The tutorial on the wiki says that to modify a part's behaviour you override methods in PartModule, but I'm at a loss as to how to use onUpdate() to do anything really when in Part there's a whole bunch of seemingly far more useful methods. Basically, what is the technique to use the methods in Part vs the methods in PartModule?

Link to comment
Share on other sites

The main difference is that a given part only has one class deriving from Part, and it can have many different classes deriving from PartModule. The latter is definitely the more flexible system. The vast majority of projects won't require Part.

You can still get a reference to the Part from a PartModule, so most of those methods are still accessible. PartModule has different (fewer) overrides, but it's not really more limited than Part; you can still get access to those events or just run checks during Update/FixedUpdate.

tl;dr use PartModule, it's much more modular.

Link to comment
Share on other sites

Thanks for your reply. I just need a bit of clarification (I have used 0 C#, so could be a total newb question): How can I access the events in Part? I want to make something that when it splashes down activates airbags, and I know I can do it using onSplashdown() or checkSplashed(), but I can't find how to actually use those.

Link to comment
Share on other sites

You can't hook into those like you would with a C# event (those exist, but KSP and Unity don't use them). You might be able to register a callback with Vessel, but your best bet is just checking each frame for the current state of the vessel.

Link to comment
Share on other sites

Okay I realize (after finding out what the icons in microsoft visual studio actually mean -_- (I'm used to code::blocks)) that I used the wrong terminology. I have no idea how to use C# events. What I want to do (and maybe this is just a bull-headed C++ way of doing it) is override onUpdate() to run part.isSplashed(), because I can't find a way to override part.onSplashdown() which seems like it would be simpler. Since the class for the plugin is in partModule, how can you refer to that partModule's instance of the part class to access isSplashed?

Link to comment
Share on other sites

Okay that's what I thought, but is there a way to access part's methods from partModule or vice versa?

No.

Some of them have equivalent calls (many unfortunately undocumented due to unity using it's own method calling system rather than overrides) such as OnPutToGround() or OnPartPart() and some are done using different methods.

For splashdown I believe there's a callback in GameEvents that covers vessel state change that you can register a function with to have called in that event.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...