- Home /
Trying to destroy all children, but they don't disappear (no errors)
I've got an object ('DotsHolder'), which is the parent object to many gameobjects. I would like to destroy all these objects.
I'm calling destroy on each of the child.gameobjects, but after going through the list they all remain. I see no errors in the console.
Transform dotHolder = this.transform.FindChild("DotsHolder");
Debug.Log("Destroying: " + dotHolder.GetChildCount());
for(int i=dotHolder.GetChildCount()-1; i>=0;--i){
Destroy(dotHolder.GetChild(i).gameObject);
}
Debug.Log("Remaining: " + dotHolder.GetChildCount());
In the log at this point I see:
Destroying: 244
Remaining: 244
Why is the 'remaining' count not zero at this point?
Comment
Your answer
Follow this Question
Related Questions
Is "null" the best way to unparent a child? 1 Answer
Transform child object over time and then destroy it. 1 Answer
Destroy Child of Game Object 2 Answers
Delete children of Instantiated object 2 Answers
Child Transform 1 Answer