Spawning Objects in Unity without the Clutter
Normally, when instantiating gameobjects in Unity, the hierarchy will look like this
As you can see, the hierarchy is getting crowded of enemy clones.
It doesn’t look too well right now, even less if we have hundreds of gameobjects
So, a nice way to tidy up this issue is as follows:
- Create an empty gameobject as a child in SpawnManager gameobject. It can be called EnemySpawnner
- Create a reference to EnemySpawnner gameobject in SpawnManager script. It can be enemySpawnner. Save the script.
- Drag and drop the EnemySpawnner child object from hierarchy to its reference in SpawnManager
- Create a new GameObject variable, it could be newEnemy, and assign to it an instantiate function
- Set enemySpawnner as newEnemy’s parent
As you may notice, the hierarchy isn’t crowded anymore with enemy clones