Clear the clutter!!

Time for a little re-organization

Following on from my last article on creating a Spawn Manager. You will notice that if you leave the game running for a while without killing any of the spawned enemies the hierarchy will soon fill up.

Enemies filling up the hierarchy

All of these extra GameObjects appearing in the hierarchy can make the testing process more difficult. We can easily prevent this build up by looking at how we create our GameObjects.

The Instantiate method has several different options to consider when we use it. Taking a look at the API for the Instantiate method, we can examine those different options —

From the Unity scripting API

If we remind ourselves how we used this method in our Spawn Manager —

Instantiate(_enemyPrefab, spawnPos, Quaternion.identity);

Here we have called the method using the ‘_enemyPrefab’ as our Object, a Vector3 variable ‘spawnPos’ for our position and a default rotation.

We have another option very similar to this that takes an extra argument when called — a Transform. As you know, this is a component common to ALL GameObjects.

Creating a new serialized variable of type Transform, we can assign this in the inspector and add it into our Instantiate call —

private Transform _enemyParent;
Instantiate(_enemyPrefab, spawnPos, Quaternion.identity, _enemyParent);

With these changes in place, we can create a new empty GameObject in our hierarchy to house our spawning enemies —

Running our game again and letting the enemies continue to spawn, we can see that we can keep a nice clean hierarchy. If you do not need to see the enemies in the hierarchy while you’re testing, you can simply collapse them to hide the contents.




A UK based Unity Developer with a passion for gaming and coding

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

Recommended from Medium

Data Scientists: Write your Medium Articles in Jupyter

CS 373 Fall 2020: Kyle Wang

Post Covid Hack Live Broadcast Recap

FEG Token AMA With SatoshiStreetBets Telegram @SSBtalk

Neo Mainnet Maintenance Notice

Readymag quarter updates: don’t miss our new pixel-precise functionality

Engineering Levels

What is important to know about Web Development

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
Les Street

Les Street

A UK based Unity Developer with a passion for gaming and coding

More from Medium

From Prototype To Work Of Art

“Game Feel”: The Impression Of Danger

OnCollisionEnter() vs. OnTriggerEnter()

Simple Player Movement in Unity