Deleting Child Objects Recursively in Unity

It took me a bit of Binging to find a method that worked the way I needed.

1st, create a public GameObject to hold the parent of the items you are looking to delete. Set this either from the Unity Editor or in code.

Then simply call a foreach loop on the parent GameObject as below to delete all children.

<br />
foreach (Transform child in searchResultParent.transform)<br />
{<br />
     Destroy(child.gameObject);<br />
}<br />

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.