Legacy Documentation: Version 5.0
Language: English
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

EditorUtility.CollectDeepHierarchy

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public static function CollectDeepHierarchy(roots: Object[]): Object[];
public static Object[] CollectDeepHierarchy(Object[] roots);

Parameters

rootsArray of objects where the search will start.

Returns

Object[] Array of objects heirarchically attached to the search array.

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); } }