Jump to content

Event for when a part prefab is loaded during game startup?


Recommended Posts

Apologies if I'm missing something obvious... but how do I set up a hook to get notified when a part prefab is loading during game startup?

For loading a PartModule (if it's one I've implemented), I can just override OnLoad, and then check for HighLogic.LoadedScene == GameScenes.LOADING.

But what about the part itself?  e.g. as each part is loaded during startup, I want to run some code that does stuff with it.  Where do I hook in?

Thanks for any suggestions!

Link to comment
Share on other sites

  • 3 weeks later...
On 1/27/2019 at 1:19 PM, Snark said:

But what about the part itself?  e.g. as each part is loaded during startup, I want to run some code that does stuff with it.  Where do I hook in?

There is no such event in the stock API that fires on a per-part basis during/after prefab creation that I'm aware of.

Off the top of my head, a few alternate solutions present themselves that might be of use, depending on the original intention.

1.) Stock API does offer an 'OnGameDatabaseLoaded' event.  Subscribe to that and iterate the loaded parts-list, running your actions/etc on them.  Its not per part, but does give an opportunity to manipulate prefabs before they are cloned anywhere.
2.) ModuleManager offers a post-configs-loaded callback where you could manipulate configs or run actions -before- the prefabs are created/loaded.
3.) Do use a PartModule.  Patch/add it into the part in such a manner so as it will always be the last module, and use the PartModule's overridden life-cycle methods to manipulate the Part.  More of a hack/workaround, but sometimes that's how it goes :)

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...