- Home /
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?
That is the usual way. You have gameObject children that don't have a transform - like what?
I specifically have empty game objects which act more as a way to organize all the children. I suppose I could put a transform on those, I just wish it was more intuitive.
Answer by Legend_Bacon · Jan 15, 2018 at 07:32 PM
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!
Cheers,
~LegendBacon
Answer by getyour411 · Jan 15, 2018 at 06:59 PM
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.
Your answer
Follow this Question
Related Questions
Can You Convert a Transform into an Image? 2 Answers
Assign multiple childs as gameobjects through script 1 Answer
This does not make sense this.gameObject.transform.Find() why? 2 Answers
Instantiating a new gameObject as a child of a different gameObject 2 Answers
How to move a gameObject without affecting its childrens' positions? 2 Answers