Jump to content

How to add partmodule to part at the main menu?


Recommended Posts

I have a small mod which is designed to calculate the volume requirements for parts if they don't have a ModuleCargoPart, and (right now) is creating a MM file so that the next time the game is loaded, the module is there.  I'd like to be able to add the ModuleCargoPart directly to avoid the need for a restart.

I've tried this:

                        ConfigNode node = new ConfigNode("ModuleCargoPart");
                        node.AddValue("packedVolume", volume(availPart, num).ToString("F0"));
                        availPart.partConfig.AddNode(node);

which doesn't work.  I also tried this which fails with an exception:

                        ModuleCargoPart mcp = new ModuleCargoPart();
                        mcp.packedVolume = volume(availPart, num);
                        availPart.partPrefab.Modules.Add(mcp);

This is all running in a MonoBehaviour.Start, which runs when the MainMenu is reached.

 

What am I doing wrong?

 

Thanks

Link to comment
Share on other sites

In my experience, adding a PartModule at runtime causes problems. It seems that every part has a fixed-length list of PartModules, defined at game startup, and if you add PartModules you get log messages about "bad PartModule index", or something like that.

Best workaround I found is to avoid PartModules in this case, and working directly with MonoBehaviours, that can be added at runtime without problems, but do not get saved in the sfs files.

If you need persistency, you need to add a PartModule, but you have to do it via MM.

Link to comment
Share on other sites

2 hours ago, peteletroll said:

In my experience, adding a PartModule at runtime causes problems. It seems that every part has a fixed-length list of PartModules, defined at game startup, and if you add PartModules you get log messages about "bad PartModule index", or something like that.

Well, there is some way to do it, since the game does it when loading :=)

2 hours ago, peteletroll said:

Best workaround I found is to avoid PartModules in this case, and working directly with MonoBehaviours, that can be added at runtime without problems, but do not get saved in the sfs files.

Not possible in this case, since it needs to be a ModuleCargoPart

2 hours ago, peteletroll said:

If you need persistency, you need to add a PartModule, but you have to do it via MM.

I know, have that working, but would like, if possible, to avoid the double-load

 

Which is why I asked the question :-)

 

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