Spawning Objects in Unity without the Clutter

Ernesto Rocha
Jun 7, 2021

We created a Spawn Manager that would spawn Enemy game objects till the end of the program, but they were cluttering the Hierarchy when generated, so we need to fix that.

In order to clean the hierarchy, we need to do this:

Add the variable
The Coroutine

First, we need to declare the global variable of data type “GameObject” to represent the enemy container.

Second, inside the coroutine, we declare a variable “newEnemy” with the instantiate function.

Third, assign the new enemy as a parent to the enemy container through each transform component.

And voilá! No more problems.

--

--