Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by funfair · Jan 31, 2012 at 09:59 AM · arraychildarrange

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 ?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image syclamoth · Jan 31, 2012 at 10:31 AM 0
Share

You'll need to sort them by name, as well. I can tell you how to do that in C#, but nobody ever wants that...

avatar image funfair · Jan 31, 2012 at 10:48 AM 0
Share

i mean, except that sorting them in script by getting their name. there is no way i can change how they arrange in unity by default? as by default they will arrange according which have been create 1st.

just feel that it is so unfriendly that once i have any changes i'll need to write another line of code for the arrangement.

avatar image syclamoth · Jan 31, 2012 at 11:07 AM 0
Share

Well, there's no way to predict what order they will be in in the transform tree. The objects get added in some opaque way, and it almost never matters.

5 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by funfair · Feb 10, 2012 at 07:59 AM

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image vbbartlett · Mar 21, 2013 at 02:44 PM 0
Share

From my experience (limited) it is by order created in the hierarchy. While it is by when they are added if created and added at run time.

avatar image
0

Answer by Paulius-Liekis · Jan 31, 2012 at 01:00 PM

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image vbbartlett · Mar 21, 2013 at 02:43 PM 0
Share

Actually there are some guarantees and there are times that you need to rely on order... example NGUI uses the order of children to display tables and grids.

avatar image
0

Answer by Kryptos · Jan 31, 2012 at 01:19 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Matfrog2000 · Feb 07, 2014 at 04:36 PM

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).

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by AShim-3D · Jun 05, 2014 at 12:33 PM

Util than allow you to sort children by name https://gist.github.com/AShim3D/d76e2026c5655b3b34e2

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Zaddo67 · Oct 25, 2014 at 01:01 AM 0
Share

Thanks Ashim. Just what I needed.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Code will not compare a child gameobjects tag to another 1 Answer

Card arrangement 1 Answer

Create array of children in Start function, use it in Update? 1 Answer

How to arrange list 3 Answers

store/rearrange integers for a basic scoreboard with C# 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges