Quantcast
Channel: Answers for "How to get all GameObjects in Scene?"
Viewing all articles
Browse latest Browse all 20

Answer by Albazcythe

$
0
0
Here's what I did without using *Resources.FindObjectsOfTypeAll* Also unlike *FindObjectsOfTypeAll*, this one returns the array elements in a parent->children order. **Edit:** Replaced main foreach loops with for loops for better performance. void Start() { List allGOs = new List(); GameObject[] rootGOs = gameObject.scene.GetRootGameObjects(); for (int i = 0; i < rootGOs.Length; i++) GetAllChildren(rootGOs[i].transform, allGOs); //Print them all out foreach (GameObject g in allGOs) Debug.Log(g.name); } void GetAllChildren(Transform current, List arrayToFill) { arrayToFill.Add(current.gameObject); for (int i = 0; i < current.childCount; i++) GetAllChildren(current.GetChild(i), arrayToFill); }

Viewing all articles
Browse latest Browse all 20

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>