Spawning Objects in Unity without the Clutter

Andrew Crippen
Apr 30, 2021
Enemies cluttering the hierarchy

This is a quick follow-up to my last article on coroutines just to show how I declutter my hierarchy when instantiating enemies with my SpawnManager.

First I created an empty gameobject and named it Enemy_Container.

Empty GameObject named Enemy_Container

Now in my SpawnManager script I created a private Transform variable named _enemyContainer and serialized the field.

Now I click my Spawn_Manager and drag the Enemy_Container gameobject into my serialized field on the SpawnManager script.

In my SpawnManager script after instantiating the newEnemy in my SpawnRoutine coroutine I add a line that sets this newEnemy’s transform parent to be the enemyContainer

How it looks with the new line that changes the transform parent

Now when enemies are spawned they go directly inside the Enemy_Container in the hierarchy instead of cluttering it up.

Enemies spawning into the Enemy_Container

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Andrew Crippen
Andrew Crippen

Written by Andrew Crippen

Unity Developer/C# Programmer for VR, 2d,3d Games and other Immersive Interactive Experiences

No responses yet

Write a response