set all the children of one object inside the same array

hello everyone, i am trying to make a space engineers like game, its supposed that you wiull be able to create your own vehicles, bases, weapos, etc. in a minecraft block placing sort of way. the script im having problems with is supposed to categorize the block that has been placed inside an array. that way i will be able to know how many engines will aplly thrust, how much will it weigh, and other sort of important stuff. i am trying to categorize them the following way:

using UnityEngine;
using System.Collections;

public class Cube_manage : MonoBehaviour {
	
	public Transform selectedChild;
	
	public Transform[] chasiBlocks;
	public Transform[] gyroscopes;
	public Transform[] engines;
	
	void Update () {
		for (int i = 0; i < transform.childCount; i++){
			selectedChild = transform.GetChild(i);
				if (selectedChild.tag == "Engine"){
					selectedChild = engines[engines.Length ++];
					break;
				} 
				
				if (selectedChild.tag == "Chasi"){
					selectedChild = chasiBlocks[chasiBlocks.Length ++];
					break;
				}
			
				if (selectedChild.tag == "Gyro"){
					selectedChild = gyroscopes[gyroscopes.Length ++];
					break;
				} 
		}
	}
}

when a block is placed its automaticaly asigned to an empy object containing all the blocks of that spesific vehicle. all i have to do is to check the newly placed block’s tag and that way it will put it in a array. i do not now how to make tis work, what yous ee above is the only thing that came to my mind. if you can give me any tips or ides on how to fix the code it will be much apreciated.

kind regards,
Thenachotech

I believe that each array needs to have it’s size updated on the fly. Your code doesn’t know how big the array needs to be in order to hold the Transforms the user is adding.
When the user adds a new Object (Transform), you need to update the size of the array.
Also, with the way your code is currently typed out, it’s going to be constantly increasing the size of the array, regardless of how many child objects it has.

Here is what I tried:

using UnityEngine;
using System.Collections;

public class Cube_manage : MonoBehaviour {
	
	public Transform selectedChild;
	
	public Transform[] chasiBlocks;
	public Transform[] gyroscopes;
	public Transform[] engines;

	private int partsAmount = 0;

	void Update () {
		if (partsAmount < transform.childCount) {
			for (int i = 0; i < transform.childCount; i++) {
				selectedChild = transform.GetChild(i);
				if (selectedChild.tag == "Engine"){
					engines = new Transform[engines.Length + 1];
					engines *= selectedChild;*
  •  			Debug.Log ("New Engines Length: " + engines.Length);*
    
  •  			break;*
    
  •  		}*
    
  •  	}*
    
  •  }*
    
  •  partsAmount = transform.childCount;*
    
  • }*
    }
    I tested my sample and it seems to be working out quite well. At the beginning of each Update frame, I check to see if the amount of children inside of the GameObject has changed since the last frame. If so, it will run the code to add the new Transform into the array. After doing so, it will store the amount of children it has into the partsAmount variable. If no new children are added, there’s no reason to run that code.
    I only used one of the arrays… but you should be able to copy it and apply it for the other arrays.
    Good luck.