Day 14: Spawning Objects With Less Clutter

As I mentioned last time, the hierarchy gets way too cluttered when more and more enemies appear in game. If we end up with a lot of enemies on the screen, the hierarchy could be completely filled up and really annoying to navigate. Lets fix that!

First we need to create another empty game object that will hold these enemies. Here we can right click on the Spawn Manager and create an Enemy Container as a child object.

Not it appears underneath the Spawn Manager, and an arrow appears next to the Spawn Manger. If we were to click that arrow, it would hide any of the Spawn Manager’s “children”, which would hide the Enemy Container and it’s children.

Next we need a reference to this new object in the code. We can add a new variable to spawn manager like so.

We also need to assign the enemy container to this script in the inspector.

Now lets modify the actual enemy-spawning coroutine, so that new enemies will be “inside” the enemy container.

We can assign a local GameObject variable to the instantiated enemy in order to “save” it, so we can continue modifying it in the code. On the next line, we can then assign its parent to the enemy container. This means the enemy is now a child of the enemy container, and will show up underneath it in the hierarchy.

As a result, now when the game is played, all the new enemies are placed neatly within the enemy container, so the hierarchy can remain clean.




I’m a passionate and talented software engineer seeking an opportunity in game development.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How I Fixed an OutOfMemory Exception Due to Custom Tiles on Google Maps in My App

5 Useful Kotlin Extensions for Android Developers

10 Flutter tips — season 2 — part 5/10

HUAWEI Location Kit Location is essential for many apps and developers need services for getting…

How to create Array List in Kotlin Android ?

Here are some of the major features of Android 12

How to make a complete registration page for application in android studio

Android Phantom Widget ID(幽霊ウェジェットID)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Blake Zoeckler

Blake Zoeckler

I’m a passionate and talented software engineer seeking an opportunity in game development.

More from Medium

Cleaning up Clutter while spawning objects

Game Development: Beginners Prospective

2.5D Platformer: Moving Platforms

How to Add a Custom Skybox