How unity arrange an Object's child ?

i have an Object with some child named 1-9, i try to use a “for” loop to get it’s child, i’m able to get “1” as 1st child, “2” as 2nd and so, but after i rename it in hierarchy. the arrangement get mess up. I get “6” as 1st child, and then “7,8,9,1,2,3,4,5”.

i wonder how unity actually arrange it ? and how do i suppose to rearrange it ?

You shouldn’t not rely on order of children. Unity doesn’t give any guarantees about that order.

At runtime (as well as in the hierarchy view), child objects are sorted by name. This is a side effect of the Transform.Find() method that needs a heuristic (alphabetic-order) to be efficient. I’m using this property in some of my scripts, so I’m prety sure it’s true.

Note: On the other side, in the project view, child are sorted by InstanceID. This doesn’t matter but it is quite confusing.

Edit: show us your piece of code with the for loop, maybe there is something wrong here.

it’s actually not the matter of my code, im just wondering about this, and i believe they are putting in a array list right after they are create or put in to a parent, if you rename it when it already inside it’s parent, the arrangement will still remain the same, so i don’t think it’s arrange by name, although it is when the moment you put it inside a parent

To solve this problem, you just have to drag all the childs out of their parent and drag them back inside the parent in the order you want it to be. After that they all will be in the correct order (the order you put them in).

Util than allow you to sort children by name