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.

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!

It does exist in the editor (at least in Unity 2021.3).

Right click on your GameObject > Select Children.