Spawning Objects in Unity Without the Clutter
In Unity if you have multiple things that are spawning your hierarchy can quickly get cluttered. This can make it hard when you want to start debugging. To help with this problem you can add containers inside the Spawn Manager to hold the different objects that you spawn. To create the container right click on the Spawn Manger then choose Create Empty. This will create the object which you can name for what it will contain.
Next, in your Spawn Manager script you need to create a variable that will reference your container. Don’t for get to add SerializeField above it so that in the Unity Editor you can drag and drop the container into the variable field.
[SerializeField]
private GameObject _enemyContainer;
Lastly, when you spawn new objects you need to make sure they are added to the container. First when you initialize the new object you need to save it to a GameObject variable. With this you can set the parent of its transform to the transform of the container variable. Make sure you are setting it to the transform and not the GameObject as that is not allowed.
GameObject newEnemy = Instantiate(_enemyPrefab, posToSpawn,
Quaternion.identity);
newEnemy.transform.parent = _enemyContainer.transform;
Doing the will help to keep your hierarchy clean and easier to debug.
Good Luck Adventurer!
-Chris