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)

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



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.