It is kind of strange things, but if you'll try to destroy child objects with DestroyImmediate
function, then you will have unpredictabe result.
In my case Unity did not destroyed all childs, but did it for only half of them.
foreach(var child in parent)
{
DestroyImmediate(child);
}
This is how i destroy children in Edit Mode:
for (int i = this.transform.childCount; i > 0; --i)
DestroyImmediate(this.transform.GetChild(0).gameObject);
As one guy consider in link it is possible with creating temp array/list.
For example:
var tempArray = new GameObject[parent.transform.childCount];
for(int i = 0; i < tempArray.Length; i++)
{
tempArray[i] = parent.transform.GetChild(i).gameObject;
}
foreach(var child in tempArray)
{
DestroyImmediate(child);
}
Link that helped me: http://answers.unity3d.com/answers/678073/view.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With