- Home /
Retrieve All Child Objects
I want to retrieve all child game objects from parent game object. For this requirement I search other posts but didn't get any useful information.
So I create new post to correct my problem. Following image illustrate my problem correctly.
I have cell collection object in hand and through which I want to retrieve all the child objects. Although children have different tag attached so I can't use GameObject.FindObjectByTag("");
So what is the efficient way to retrieve child game objects?
Answer by Munchy2007 · Feb 22, 2014 at 11:37 AM
Maybe something like this would do what you want?
// C#
foreach (Transform child in transform)
{
// do something with child here
}
You would use this on the parent object.
This is the usual way to access the direct childs of a gameobject. However you have to be careful what you do inside the foreach loop. You can't destroy the childs in such a loop since that would change the collection you're iterating over.
In general it's a good idea to include in the question why you want to do something because not all situations have the same solution ;) Also since Unity has 3 different languages (UnityScript, C#, boo) it would help to specify what language you use to get a more suited answer.
Right. and that's also not recursive. if you want to get all the children recursively, consider just gameObject.GetComponentsInChildren < Transform > ()
Your answer
![](https://koobas.hobune.stream/wayback/20220613134337im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Get components in children and childrens children and so on 1 Answer
How Should I Get a List of Child Objects 2 Answers
get bone path from transform 1 Answer
how to find, not a specific child (GetChild(0)), but a range of child objects (GetChild(0 to 4)) 1 Answer
How to move the parent object to a child of one of its children? 1 Answer