Hello! I was under the impression based on lots of forum posts that GetComponentsInChildren would return the object selected, all of it’s children, and all their children etc. This doesn’t seem to be happening as when I run the code below, I only get results from the immediate children.
Any thoughts?
static function ShowPolycount () {
if (Selection.activeObject.GetType() == UnityEngine.GameObject)
{
var totalTriCount : int = 0;
// Get count of parent object if applicable
if (Selection.activeGameObject.GetComponent.<MeshFilter>())
{
var parentMesh : Mesh = Selection.activeGameObject.GetComponent.<MeshFilter>().sharedMesh;
var parenttri : int = parentMesh.triangles.Length / 3;
totalTriCount += parenttri;
}
// Get count of all children of object
var allChildren = Selection.activeGameObject.GetComponentsInChildren(Transform);
for (var child : Transform in Selection.activeGameObject.transform) {
print ("Object: " + child.name);
if (child.gameObject.GetComponent.<MeshFilter>())
{
var objMesh : Mesh = child.gameObject.GetComponent.<MeshFilter>().sharedMesh;
var triCount : int = objMesh.triangles.Length / 3;
totalTriCount += triCount;
}
}
print ("There are " + totalTriCount + " triangles.");
}
}