How Should I Get a List of Child Objects

I am wanting to get a list of a gameobject’s children, but I’m not sure what the best way to do this is. I know I can use transform as I’ve already looked around for an answer on the forums, but I feel like that is a pretty ridiculous way to get children. What happens if the children don’t have a transform?

Hello there,

Just to clarify: all GameObjects in the hierarchy have a Transform. Unity cannot work with an object that doesn’t have one.

As far as I know, going through all the children in transform.childCount remains the best method to get a list of a GameObject’s children. Otherwise, you can always find them depending on the components or tags they have.

Hope that helps!



You don’t have to “put” a transform on an empty gameObject, it is already there; I’ve not seen anything that would make the standard method “ridiculous” so I’m posting as an answer.