Jump to content

How to add a new part


Recommended Posts

Hello!

Anybody help my with understanding "how can I add a new part from code-behind"?

I create a new part form PartLoader. After, I set parent for a new part. And I create PartJoint. But I did't see a new part ((

Do you have any ideas?

Thanks!

Link to comment
Share on other sites

Can you post the exact error?

maybe the code that makes the error?

from what you wrote, it's quite hard to guess where the problem is..

For example:


[FONT=arial]var my_part =PartLoader.getPartInfoByName("blablabla").partPrefab;[/FONT][FONT=arial]
var parent_part = FlightGlobals.ActiveVessel.rootPart;
my_part.setParent(parent_part);
my_part.attachJoint = PartJoint.Create(my_part, parent_part, my_part.srfAttachNode, null, AttachModes.SRF_ATTACH);
[/FONT][FONT=arial]FlightGlobals.ActiveVessel.Parts.Add(my_part)[COLOR=#DCDCDC];[/COLOR][/FONT]

As I understood, I get incorrect coordinates for attachJoint.

Edited by belpyro
Link to comment
Share on other sites

I have no experiance with adding parts to existing vessels..

My project has to do with spawning one-part-vessels..

there I use ship construct..

ShipConstruct newShip = new ShipConstruct();

newShip.Add(newPart);

not sure if that is relevant for you though.. - if you need the joints, I failed with them myself last time, so I can't help..

however - you should take a look at KAS git repo..

They do that new-part-on-the-fly thing quite stable..

Look for the "attach" code that's used when you attach a KAS pipe or something..

Link to comment
Share on other sites

  • 1 month later...
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...