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
4
Question by TheMorten · Nov 29, 2011 at 01:16 PM · hierarchyfindroot

Is it possible to get all root transforms of the scene hierarchy?

Hey Unity folks! As the title implies I would like to find all root transforms in the scene hierarchy, via a C# script.

Here's the catch: There are a lot of children for each transform.

So far the methods we've found are:

  • Traverse all GameObjects and check if transform.parent == null... This is very slow since we have a lot of child transforms.

  • Keep track of which GameObjects are roots and add a root tag appropriately (then find them using GameObjects.FindObjectsWithTag).

Is there a more elegant way of finding all root transforms in the scene hierarchy?

Comment
Add comment · Show 2
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 thienhaflash · Nov 06, 2012 at 04:14 AM 0
Share

I really want to know this also. Especially when the GameObjects are inactive, we can't normally find them. How can we traverse through thousands of GOs just to find several root GameObject ? I know that Resource.FindObjectsOfTypeAll should do the trick but it's terribly slow, why should I search the whole project just to find several root scene object ? Anyone have a better idea ?

avatar image yoyo · Dec 14, 2013 at 12:12 AM 0
Share

Duplicate of http://answers.unity3d.com/questions/27729/finding-the-root-gameobjects-in-the-scene-.html

2 Replies

· Add your reply
  • Sort: 
avatar image
13

Answer by DonKanallie · Jan 15, 2016 at 08:42 AM

With a recent Unity version (around 5.3) the preferred way would be

 UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects()
Comment
Add comment · Show 2 · 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 thienhaflash · Jan 27, 2016 at 04:09 AM 0
Share

Seems that method .GetRootGameObjects() not found in Unity 5.3.1, are they removed it ? :(

avatar image krgemlic thienhaflash · Mar 19, 2016 at 01:17 PM 1
Share

Available since 5.3.2 http://unity3d.com/ru/unity/whats-new/unity-5.3.2

avatar image
0

Answer by sparkzbarca · Nov 06, 2012 at 04:34 AM

no of course there is no way to quickly search thousands of things for a few specific things.

However its worth asking yourself how these objects get generated to begin with.

If these roots are really important to you you have a few choices.

  1. Search during load and store the result (lets be clear here, once you find these objects or any really you store them in a variable so you dont have to run another search again, that is irregardless of the way you search)

  2. Store them during generation, it seems to me that when a parent is created you should simply shuttle it off to an array of transforms for later access. Is there a reason this isn't viable?

keep in mind even if the parents are changing its probably less costly to mess with a small array that search a large scene.

  1. Maybe you should explain your issue in more detail and we can help you come up with an alternative way of doing something. You said each parent has lots of children, maybe thats not a good approach. It does for example result in tons of things waking up all at once on a movement. If you explained the larger context it might be that you dont in fact need what you think you need.

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

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

7 People are following this question.

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

Related Questions

How can I find a unique sibling/parent/child in a specific hierarchy and not from all the scene? 1 Answer

find next gameobject in hierarchy? 1 Answer

How to find which script disables my gameobject 1 Answer

How to get a recursive named bone transform? 3 Answers

GetComponent - Root Hierachy 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