Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Bunzaga · Jan 04, 2017 at 11:40 AM · c#orderinggetcomponents

Reliable Order of Components, using GetComponents()

Is there a way to rely on the order of components attached to a given GameObject, when using gameObject.GetComponents()?

For example, I have several 'WhateverActions': MoveObject, TurnObject, ScaleObject, WaitForTime, WaitForEvent, etc. etc. I have been able to assign several of these to a GameObject, as components, and they seem to be in order of appearance. The component I list at the top of the list, is always first. The component I list at the bottom, is always last, and the middle is sorted, etc. If I move a component up in the Inspector, it changes the order of the Array, and so on.

Can this be depended on?

If not... why not? If not, what is my alternative? Do I have to put an integer for each component, and manually make sure they are ordered in the way I want, then GetComponents(), and sort them myself based on that int?

I can't be the first person who wanted to rely on GetComponents and have them be sorted based on the way they are listed in the Inspector... Thank you for any advice and accurate responses.

Comment
Add comment
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

1 Reply

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

Answer by aliakbo · Jan 04, 2017 at 01:03 PM

The order of components in in GetComponents is always the order they are, in the inspector. This always holds and if you change the order in the inspector it will change the order in the array.

All unity versions up to now have this behavior.

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 Bunny83 · Jan 04, 2017 at 01:30 PM 1
Share

The last statement isn't true ^^. I can't remember which version actually introduced the ordering of the components in the inspector, but before that the order was kind of random. Though that was a long time ago. I think they added this feature when audio filters were introduced as they rely on the ordering of the components. As far as i remember this was during the 4.x cycle but don't take my word on it. Since 5.0 it's more or less reliably. Though they are still fixing small bugs like:

Ensure correct waking order of components when duplicating a GameObject.

Which is from the 5.0 major update

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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer

Car Positioning System 0 Answers

Implicit type GetComponent call 0 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