Quantcast
Channel: Answers for "How To Get List of Child Game Objects"
Browsing latest articles
Browse All 33 View Live

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 Article


Answer by jason891107

foreach (Transform child in transform) { //child is your child transform } This is right. GetComponentsInChildren will get gameObject's transform as well.

View Article


Answer 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 Article

Answer 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 Article

Answer 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 Article


Answer 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 Article

Answer 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 Article

Answer 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 Article


Answer by Anders_bp

Try this: for (int i = 0; i < transform.childCount; i++) { Transform myTransform = transform.GetChild(i); }

View Article


Answer 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 Article

Answer 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
Browsing latest articles
Browse All 33 View Live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>