Loop through children and their children

How can I loop through a transforms children and the childrens children so I can find every child with a certain component?

I work in c#

Try something like this;

for(i = 0; i < transform.childcount; i++){

if(transform.getchild(i).getcomponent()){

// then add to a list so you can access later. So make a list variable at top of code.

listname.add(transform.getchild(i).gameobject / or getcomponent for a component list.

}
else{
print(“null child or null component”);
}

}
}

Hows that?

To look for childrens children, add another Iteration for each child under the main iteration, so it iterates through each childs children and checks for the components aswell.

Hope This Helps!