Tidy Up the Spawning- Game Dev Series 12

How about keeps the children to where the parent is?

Previous: Makes it Keep Running with Coroutine

After we created the spawning machine, one issue pops up immediately. As the player lives the longer, the game environment gets much messy.

I’m not just talking about the gameplay, but also the hierarchy.

All the enemies spawned at the root of hierarchy which is really not easy for us to maintain, especially when you add more contents in the future.
We need to store these gameobjects into another empty gameobject. In Unity, we called this “set a parent”.

Let’s create an empty under Spawn_Manager and called it Enemy Container.

Let’s create a variable to tell the script what is Enemy Container and add a line.

Before we add a line to it, how do we give an order to a gameobject just spawned?
Even a gameobject not yet been created, we can still make a variable to it.

Set a GameObject variable named newEnemy. Then we can set the parent to it.

Now it should know where to put the spawned enemy when played the game.

A passionate gamer whose goal is to work in video game development.