[SOLVED] A way of grabbing all childs of a gameobject and put them into an array

Hello,
I was wondering if there was a way of declaring a game object as a public variable, and when that variable is assigned the code takes all children of that game object and puts them into an array.

Or, is there a method where you can instantiate a prefab object and put them into the array upon instantiating them?

If my question is not clear I can clarify.

Please help!

If you have a GameObject called foo, you can get all Transforms in it and all of its children with this:

var AllTransforms = foo.GetComponentsInChildren<Transform>();

Thank you!

1 Like