GameObject.getComponentsInChildren() unexpected array order

I just found that that order of the result will change if a child has an Animator component on it.
GameObject.getComponentsInChildren(this.gameObject, Camera);
All children are inactive but the first (top in hierarchy) and they all get collected in that order, until I add an Animator component to the last one, which then comes first in the result.

Original Post on Discord

by user 732122195614105653

Is there a sibling order property that I can use to sort the result so that it matches the hierarchy set in Unity?

by user 732122195614105653

The hierarchy order should always match the Unity hierarchy - is always the object with the animator first in the list?

i got the same problem, but no animator was involved, apparently it gets the order the children where created instead of the order in the hierarchy, my solution was to use a public objec3d array and manually set them in the inspector that way the order was respected

by user 528663425488781362

Ok - personally i wouldnt trust or rely on any order when using methods like these too (e.g. if order is crucial)

Thanks for clarifying too.