Destroy all Children in Unity

How to destroy all children of a gameobject

We finally added some thrusters to our enemies, but when they get destroyed the play an animation. This prevents us from destroying the game object for visual reasons, until the animation is finished. The thrusters are childs of the enemy game object. When we start of enemy death sequence we use the following code to destroy all children:

foreach(Transform child in this.transform)
{
Destroy(child.gameObject);
}

There are many ways to do this, but this seems to be the cleanest and simplest way without much code.

--

--

--

Aspiring developer that’s self-learning Unity & C# to transition to a career with Unity. I got a passion for creating interactive experiences.

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

Recommended from Medium

Infrastructure Automation: What is it? What does it do?

Infrastructure Automation: What is it? What does it do?

Simple Thresholding And Its Types In OpenCV

Add Some Logic In Python

Creating popup Chrome extensions that interact with the DOM

T Die Die

An Introduction to Coding

Code

Fire Your Engineering Team

How We Increased Garbage Collection Performance with RediSearch 1.4.1

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
Tristan Engel

Tristan Engel

Aspiring developer that’s self-learning Unity & C# to transition to a career with Unity. I got a passion for creating interactive experiences.

More from Medium

2.5D Platformer

Animating Sprites in Unity

Blood Splatters in Unity

Unity 2021 Object Pooling