Jump to content

PartModules added in VAB get removed when going to launchpad - huh?


Recommended Posts

Background:

As part of kOS, I've made a very tiny PartModule called KOSNameTag, the only purpose of which is to let the user assign any arbitrary string name they feel like to a part. All it does is add this nametag as a KSPField you can see in the RMB context menu for the part, and also add a KSPEvent button you can click on to open a little textfield widget to alter the name. (And kOS has a new function that will let you get all parts with nametag "your tag name here", so you can write a script to retrieve data about that specific one part in flight).

I didn't want to have to add this PartModule to EVERY single part in the game, ModuleManager style, but rather I wanted to give people the ability to click a button in the kOS window (that will come from the ApplicationLauncher toolbar), that says "add nametag to part" and then they can click a part and it causes that one part to get an instance of the KOSNameTag PartModule attached to it.

The Problem:

I got everything I just described above working perfectly. As long as I do it all within the same Scene. But if I add the new KOSNameTag module to the part inside the VAB, and then launch the ship, the act of going to the launchpad causes the Partmodule to get removed from the ship.

(On the other hand if I do add a KOSNameTag permanently to every part of that type, by editing the Part.cfg file, then it does work. So it's not that the *field* is missing or failing to persist, it's that the entire PartModule is being scraped off by the act of launching.)

Frustratingly, when I look at the .craft file being created by the VAB editor, it actually *DOES* contain the KOSNameTag PartModule. So it *is* being saved from the editor, but then getting removed when launching.

I'm suspecting that when launching the ship, KSP must be going back to the default definition of that part and instancing a new one from there, and then only populating those fields from the .craft file that refer to PartModules that exist in the default definition of the part, rather than instancing the PartModules that are actually mentioned in the .craft file.

Is there a solution to this that doesn't involve having to add KOSNameTag to each and every part in the game, ModuleManager style?

Link to comment
Share on other sites

Is there a solution to this that doesn't involve having to add KOSNameTag to each and every part in the game, ModuleManager style?

You could store your name in Part.customPartData and have a KSPAddon behaviour add PartModules on the fly in-scene. Otherwise, adding your PartModule to every prefab and having it destroy itself immediately in flight if it doesn't have a name is probably the way to go

Edited by xEvilReeperx
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...