Not my script. Just personal note
using UnityEditor;
using UnityEngine;
public static class GroupCommand
{
[MenuItem("GameObject/Group Selected %g")]
private static void GroupSelected()
{
if (!Selection.activeTransform) return;
var go = new GameObject(Selection.activeTransform.name + " Group");
Undo.RegisterCreatedObjectUndo(go, "Group Selected");
go.transform.SetParent(Selection.activeTransform.parent, false);
foreach (var transform in Selection.transforms) Undo.SetTransformParent(transform, go.transform, "Group Selected");
Selection.activeGameObject = go;
}
}
Save this in Assets/Editor/GroupCommand.cs
Use 'Ctrl-G' or 'GameObject Menu > Group Selected'. It also supports Undo:
Thanks to bjennings76 = https://answers.unity.com/questions/118306/grouping-objects-in-the-hierarchy.html