Is there a way to get the amount of child objects of an object? I know I can just use an int, or a List as a container for the child, but I am already assigning the object to a parent object at runtime and it just doesn’t sound efficient to also have a list going. Just curious if there are any ideas. I have a vertical layout group to hold items, as the items are instantiated I want the panel’s height to expand.
1 Answer
1Yep, there sure is,
In fact there’s a property in the transform class
called childCount, this is the number of children that the Game Object has.
the property is accessed quite easily
int someUselessInt = transform.childCount;
Link:
when ever you need something related to transform (children and parents is all Tranform stuff) or other built in class it always helps to Google that class and look up the docs and see what methods and variables it has. It can save you Hours of coding.
Hope it helps
Yep http://docs.unity3d.com/ScriptReference/Transform-childCount.html
– Fornoreason1000