EditorUtility.CollectDeepHierarchy
static function CollectDeepHierarchy(roots: Object[]): Object[];
static Object[] CollectDeepHierarchy(Object[] roots);
static def CollectDeepHierarchy(roots as Object[]) as Object[]
Description

Collect all objects in the hierarchy rooted at each of the given objects. This is most useful for linearizing entire GameObject hierarchies including all their components.

Note that the traversal will not include assets referenced from within the hierarchy. For example, having a MeshFilter component in the hierarchy will not cause the referenced Mesh to be included in the resulting list.
function Start () {

// Create two GameObjects. var parent = new GameObject(); parent.name = "Parent"; var child = new GameObject(); child.name = "Child";

// Make one a child of the other. child.transform.parent = parent.transform;

// Collect entire hierarchy. var result = EditorUtility.CollectDeepHierarchy([parent]);

// Dump results. Will log four objects to the console; // two GameObjects ("Parent" and "Child") and two Transform // components (one belonging to "Parent" and one belonging to // "Child"). for (var obj in result) { Debug.Log(obj); } }