Clean up your Spawned Objects in Unity

It’s that time of year again (at least it is at the time of writing)…time for spring cleaning. It’s the time I see my neighbours cleaning their respective garages out, readying their pools and for some reason, a lot of mattresses sprawled out on the curbs.

For us Unity developers, maintaining our virtual environment is a never ending battle…especially when we start spawning objects:

As you can see, the Hierarchy window can fill up fast. This can make it extremely time consuming if you are attempting to troubleshoot a bug during playback when you have more than a screen full of objects to sort through.

A better way is to parent the spawned objects to a folder in the hierarchy. That way with a simple click of the triangle, you can quickly organize your objects:

The first step is to add an empty game object to your scene and reset it’s transform:

Next, we need to assign this new object as the parent. Let’s take a look at how we can accomplish this with our code.

First we need to assign the transform of our container:

And lastly we set the parent within the Instantiate argument:

It’s the last argument in the above line of code that assigns the parent of the object.

Now you can have a clutter free hierarchy!




Unity Developer

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

Recommended from Medium

Array in Ruby — detailed info!

The simplest way to navigate and operate your microservices

Spin up a Kubernetes cluster easily with K3S

Photo by Matt Hardy from Pexels

Wekor Tryhackme Writeup

Install the Python Environment for AI on Linux

Terraform Optional Variables and Attributes — Using Null and Optional Flag

What’s New on Agile? —  October 2021

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
Mike Brisson

Mike Brisson

Unity Developer

More from Medium

Learn to code by making 2 D space shooter game.

2D Galaxy Space Shooter

Making a Player move in Unity

Coroutines with Unity