How to go about mounting weapons on spaceships and storing these.

I have a space ship game im making that I want to allow mounting of weapons and then firing them in script. I have many different factions and ship classes/types.

I will create my weapons as prefabs and then call the appropriate weaponControl script on each weapon to perform the firing from each ship’s central control script.

My question is dealing with my central script on each ship that controls calling the appropriate functions on each weapon. I know i’ll have a list of each weapon and its control script to call. The biggest problem is how i populate this list (as each list has a different size compared to other ship classes) and how i can store the wanted locations and rotations for each weapon slot the ship has, when i also have to take into account different ship classes/types. If i add a weapon to the ship, i wnat it to fill the first most weapon slot of its type and is then parented to the ship at local position defined in the weapon transform arrays in the ship’s central script.

How do i make different weapon and location/rotation arrays for every ship class?
I know I use the inspector, but how do i do this for every ship if the array is of transforms to store position and rotation of each weapon slot?

Can do do this in script and have a separate script per ship?
Would it be inefficient if i have empty gameobjects with position/rotation i want for each slot parented to the ship for script reference? How ineffective would this be in mobile?

Nothing bad about empty game objects from a performance perspective (no draw calls since it doesn’t have a renderer and very low mem overhead, plus you have to store it somehow). There are lots of ways to skin this cat and empty objects is one of them. Create a prefab for each of your ship types with empty objects for the locations. Then reference them in the ship script.

public transform weaponLocationStarboard;

You could also add a script to your “empty” object so that you can add info to your weapon locations.

When I have a lot of objects subbed to something I’ll usually have a class/script I attach so I can do something like:

private MyThing[] myThings;

void Start () 
	{
		//get ALL the things
		myThings = this.GetComponentsInChildren<MyThing>().OrderBy(n => n.ID).ToArray ();
	}

In some situations it’s a lot easier (e.g. 20 slots you need ordered from id 1-20).