private static IEnumerable <GameObject> GetEverythingInHierarchy() { var scene = SceneManager.GetActiveScene(); var root_objects = scene.GetRootGameObjects(); foreach (GameObject @object in root_objects) { yield return(@object); var descendants = TransformUtils.GetAllDescendants(@object.transform); foreach (Transform t in descendants) { if (t != null) { yield return(t.gameObject); } } } }