Jump to content

Exploiting the new inventory system to add modules to parts?


Recommended Posts

I've been noodling around with an idea to use the new inventory system to add modules to parts by installing inventory items.  It was inspired by the new evaExperiment, where an inventory item gatekeeps a module.  1.11 does this in a very simple way  where having the item in inventory simply enables an existing experiment module.

The full idea would basically be a way to create modular parts where a part isn't much more than an empty shell and the inventory items add the functionality you would want.  A part would be created from the physical part (say an Octo probe shell) with a bunch of inventory slots and a volume limit.  You would then use inventory items to add command, SAS, reaction wheel, comms, etc.

This would allow you to add things like science experiments to probes or SAS to capsules (assuming you can stay within the volume limits!), enable upgrading existing parts, use the tech tree to shrink the volume for inventory items to cram more stuff in a part 'shell', etc.

The only way this would work is rather than the current 'gatekeeper' method where the module is already on the part, you would need to be able to propagate a module 'upwards' from the inventory item to the host part.

So before I dive in I thought I would ask has anyone tried to dynamically adding a module to a part or know if it's possible or not?  If so is there some sample code for this?  I would like to avoid spending time on either the impossible or on a known and solved problem.  Also, maybe someone is already on this or it's just a stupid idea for reasons I haven't thought yet.  I would want to hear about that as well.

Thanks!

Link to comment
Share on other sites

  • 2 weeks later...

I've recently explored the idea of adding partmodules at runtime and if I remember correctly, parts without backing .cfg module entries are incorrectly restored from the persistence file on load, so you'll have to write your own code to handle that. I haven't seen any examples of code though, only claims of success.

Link to comment
Share on other sites

17 hours ago, ktosiu said:

I've recently explored the idea of adding partmodules at runtime and if I remember correctly, parts without backing .cfg module entries are incorrectly restored from the persistence file on load, so you'll have to write your own code to handle that. I haven't seen any examples of code though, only claims of success.

That was sort of my thinking.  My hope is that because a module is written in the cargo part cfg, it avoids that issue.  On load the code would simply (ha!) insert any tagged modules of cargo parts into the containing part.  The part in effect is the module, so it automatically gets added while in inventory.

If you were able to at least insert part modules dynamically that's promising.  I know basically nothing about C# or Unity so nearly all of my KSP coding has been at the 'banging on it with a rock until it stops moving' phase.  I'm hoping to progress to at least the 'poking it with a sharp stick to get it to move in the direction I want' level.  Knowing there's a stick is helpful.

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