Is the array returned from Unity - Scripting API: Component.GetComponentsInChildren always in the same order?
For anybody landing here, it does:
http://forum.unity3d.com/threads/getcomponentsinchildren.4582/#post-33983
And if it does not, I’m about to get into trouble …
The order is undefined.
this is a long but reliable way as the default order is undefined.
hope it helps
public SomeComponent[] Components;
private Transform _myTransform;
void GetChildrenByOrder()
{
SomeComponent[] temp = GetComponentsInChildren<SomeComponent> () as SomeComponent[];
Components = new SomeComponent[temp.Length];
int index = 0;
int noOfChildren = _myTransform.childCount;
for (int i=0; i<noOfChildren;i++)
{
SomeComponent childComponent = _myTransform.GetChild(i).GetComponent<SomeComponent>();
if(childComponent!=null)
{
Components[index] = childComponent;
index++;
}
}
}