I am looking for all objects in a hierarchy that have meshes. This includes the object itself and any of its children. The purpose is to attach a mesh effect.
If I use:
var mesh : MeshFilter = gameObject.GetComponentInChildren(MeshFilter);
mesh.gameObject.AddComponent ("MeshExplode");
It finds the first mesh and works fine. But as I want to have all meshes I am trying the following:
var meshes : MeshFilter[] = gameObject.GetComponentsInChildren(MeshFilter) as MeshFilter[];
if(meshes)
{
for (var mesh : MeshFilter in meshes)
{
Debug.Log("Found mesh =======================================");
mesh.gameObject.AddComponent ("MeshExplode");
}
}
else
{
Debug.Log("No meshes");
}
This doesnt find any meshes and I am completely confused to why.