How to GET ALL THE CHILDREN OF AN OBJECT in Unity

Опубликовано: 01 Октябрь 2024
на канале: GDT Solutions
2,298
35

In this video we use the "GetChild" function to get all the children of a GameObject in Unity, for that we need the references of the parent GameObject or the Transform component (if we have one of these we can access to the other).
The "GetChild" function has to be called on a Transform component and requires an integer number as parameter to identify the index of the child.
A Transform component has a variable called "childCount" that tells you how many children that Transform has, we use that information to create an array of GameObjects with a certain size.
With a for loop and the GetChild function we traverse all the children of the Transform and assign them to the array.