Answer by Julien-Lynge
The suggestions I've seen from smart people like Eric5h5 is to use the build-in transform functions, rather than GameObject.Find. Since it looks like you're using C#, the following is also in C#:To get...
View ArticleAnswer by jason891107
foreach (Transform child in transform) { //child is your child transform } This is right. GetComponentsInChildren will get gameObject's transform as well.
View ArticleAnswer by Pix10
foreach(Transform child in transform) is unreliable, as is GetComponentsInChildren, as they won't traverse the entire tree of children. This will correctly return all the children: void Start () {...
View ArticleAnswer by Dinkelborg
The best Answer would be a recursive function I guess ... So the function will go and look at the first Transform it finds in transform then it will do whatever you want to do (add it to a list or...
View ArticleAnswer by pprofitt
public List Children; foreach (Transform child in transform) { if (child.tag == "Tag") { Children.Add(child.gameObject); } } In c# you can use this code to get all the child objects with a certain tag.
View ArticleAnswer by inewland
I ran into a problem recently where the loop was getting half way through the child count and stopping, weird... I fixed it with this: List children = new List(); foreach (Transform t in...
View ArticleAnswer by de-Rooij
This piece of code will place all children in an array at Start: using UnityEngine; using System.Collections; public class YourClass : MonoBehaviour { public GameObject[] children; public int i; void...
View ArticleAnswer by zd
Recursive solution that returns a list of gameobjects. List GetAllChildren(GameObject obj) { List children = new List(); foreach(Transform child in obj.transform) { children.Add(child.gameObject);...
View ArticleAnswer by Anders_bp
Try this: for (int i = 0; i < transform.childCount; i++) { Transform myTransform = transform.GetChild(i); }
View ArticleAnswer by michaelhsiu101
Hi, I wrote some static methods that allow you to recursively get all children without creating new lists every time (each call adds to a master list). public static class Utils { public static List...
View ArticleAnswer by Simflare3
My solution is similar to the accepted answer and simpler than many of the other suggestion. I have included the full code and tested it. Transform[] allChildren = GetComponentsInChildren(); foreach...
View Article