Answer by Mike 3
I'd do it via Transform instead of GameObject, but otherwise no, that'll be pretty much the fastest wayIf you use Transform instead of GameObject, you can just check if t.parent is null, if so it's the...
View ArticleAnswer by BinaryCore
Another way is that you could also use Tags to tag your root game objects with a distinct tag type like "RootGameObject" and then use GameObject.FindGameObjectsWithTag("RootGameObject") to get all the...
View ArticleAnswer by yoyo
You can find a single root object like this (C#):Transform xform = UnityEngine.Object.FindObjectOfType<Transform>(); GameObject rootObject = xform.root.gameObject;Note that this calls...
View ArticleAnswer by Adrian
In the Unity editor (**ONLY**) ... You can use following code to get all the root game objects directly (the same method is used internally by Unity in the hierarchy window): public static IEnumerable...
View ArticleAnswer by DonKanallie
With a recent Unity version (around 5.3) the preferred way would be UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects()
View ArticleAnswer by nsmith1024
GameObject[] p = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects(); This doesnt work, some active objects are not included in the list. One object that im interested in...
View ArticleAnswer by dbdenny
UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects() Will find all gameobjects in scene (both editor mode and play mode!), so I recommend to do a filter like this:...
View Article