Creating A Ship Customisation/Building System

We are currently working on a 3d (first person) flight/shooter game set in space.

We want players to be able to build and customise their own ships using a selection of parts they “purchase” using money earned form playing matches. The idea is to build up a bank of weapons, armour, cockpits and utilities which they then arrange however they want in some kind of in-game builder. Sort of like Kerbal Space Program or Spore.

We aren’t sure how to tackle this and what sort of infrastructure we need to make this. Maybe have the separate parts they have unlocked as prefabs and then instantiate them in some way where the player wants them and then find a way of connecting all the parts together once they have finished placing them?

We code in C# but can use Java, so C# is preferable if quoting any scripts. If anyone could link me some practical examples or tutorials that cover part of this that would be great!
HasALamb Games

1 Like

Yes, each piece should likely be a prefab.

You would have some kind of UI that would have each of the parts shown on screen that the players could drag around and place on their objects. You’d have a root player ship object that you could then attach child objects to:

GameObject playerShip = /*get a reference to the player's ship somehow*/;
GameObject subObject = (GameObject) Instantiate(shipPiecePrefab, pos, rot);

subObject.transform.parent = playerShip;

To keep track of what objects a players ship has you could use a Dictionary. The GameObject in this dictionary would be the prefabs themselves, not the instances attached to the player’s ship, and the Vector3 would be the objects position relative to the parent. This way you could instantiate multiple copies of this ship (in-world, ship building screen, etc.). Could be something like this

//Think of this as a blueprint from which to create the players ship
public class PlayerShipSetup : MonoBehaviour
    //Populated from your ship building UI
    public Dictionary<GameObject, Vector3> ShipPieces;

    //Instantiate the ship using the required pieces
    public GameObject BuildShip()
        var playerShip = new GameObject();
        foreach (var shipPiece in ShipPieces)
            var p = (GameObject) Instantiate(shipPiece.Key, shipPiece.Value, Quaternion.identity);
            p.transform.SetParent(playerShip.transform, false);
        return playerShip;


Could you add a bit more to your code, I am very interested in this, and I am kind of new to Unity, but not programming. I know that your time is likely valuable, but could you possibly make a demo for me to work off of?