How can I select whole object with it's childrens in hierarchy?
I'm porting my fairly large project to different render pipeline, and so I have to change materials and stuff. My problem is that I have a ton of objects that are complex (lots of "collapsed" gameobjects) and when I want to select them all by just shift clicking top and bottom, then main objects are selected but their childrens are not. Probably kinda stupid question, but is there a way to select an object with its childrens, different then expanding all collapsed objects?
GrassClump.001 was expanded during selection, GrassClump.002 was collapsed during selection.
Answer by streeetwalker · Sep 21, 2020 at 10:10 AM
i think you'd have to write an editor script to do this - Editor scripts are not that difficult, and this is a fairly simple problem. You may be able to find one already written out on the web.
I took this as a challenge, so here is the code. Paste this into a script named SelectAll.cs and place it a folder named Editor.
Then press option-a or alt-a (depending on your system) after selecting an item in the hierarchy, it will select all children recursively:
using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
public class SelectAll : MonoBehaviour {
private static List<GameObject> childGOs;
[MenuItem( "Tools/Select All &a" )]
private static void NewMenuOption() {
GameObject obj = Selection.activeGameObject;
Transform t = obj.transform;
childGOs = new List<GameObject>();
childGOs.Add( obj );
GetAllChildren( t );
GameObject[] gOs = childGOs.ToArray();
Selection.objects = gOs;
}
static void GetAllChildren( Transform t ) {
foreach( Transform childT in t ) {
childGOs.Add( childT.gameObject );
if( childT.childCount > 0 ) {
GetAllChildren( childT );
}
}
}
}
You can also choose it from the Tools menu. Enjoy!
Your answer
Follow this Question
Related Questions
activeInHierarchy code not being reflected correctly in Editor although debugging shows correct code 1 Answer
Unity forbidden deletion when selection.activegameobject is particular type 0 Answers
Set parent of dragged object to selected GameObject in hierarchy 0 Answers
Find All GameObjects currently that are in the Hierarchy Window view 1 Answer
HideFlags.HideInHierarchy not updating hierarchy in Edit-mode 3 Answers