Jump to content

Object Instantiation / Spawning


Recommended Posts

Hello... again.

I am trying to spawn a part in game during a mission. I am familiar with Unity's Object.Instantiate method, but using it in game doesn't yield any results:


print (this.transform.position);
print (this.transform.rotation);
Instantiate(this.gameObject, this.transform.position, this.transform.rotation);

The first two prints are working, and so I tried instantiating another copy of the part that called instantiate (mainly because I don't know how to pass the gameobject I actually want spawned into the method).

Searching the forum only yielded one other thread asking the same thing. He figured it out, but didn't care to share /:

Link to comment
Share on other sites

Ok ok, think I might be onto something now.



ShipConstruct newShip = new ShipConstruct();
ShipConstruction.PutShipToGround(newShip, this.transform);

So ShipConstruct and ShipConstruction are part of the KSP class library. As far as I can tell, that code instantiates a new vessel and places it at the location of the part that called the code.

The problem is, the new instantiated ship has no parts, so really its just an empty vessel. I know I can add parts using ShipConstruct.Add(part), but how do I reference/find a part?

Link to comment
Share on other sites

  • 2 weeks later...
Ok ok, think I might be onto something now.



ShipConstruct newShip = new ShipConstruct();
ShipConstruction.PutShipToGround(newShip, this.transform);

So ShipConstruct and ShipConstruction are part of the KSP class library. As far as I can tell, that code instantiates a new vessel and places it at the location of the part that called the code.

The problem is, the new instantiated ship has no parts, so really its just an empty vessel. I know I can add parts using ShipConstruct.Add(part), but how do I reference/find a part?

Look around the PartLoader class. Maybe PartLoader.LoadedParts (or something like that) is what you're looking for

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