Skip to content

Instantly share code, notes, and snippets.

@raisilhamn
Last active November 16, 2023 11:39
Show Gist options
  • Save raisilhamn/59a7ba76b1d968e61864bfaf8995ac1c to your computer and use it in GitHub Desktop.
Save raisilhamn/59a7ba76b1d968e61864bfaf8995ac1c to your computer and use it in GitHub Desktop.
Save this in Assets/Editor/GroupCommand.cs

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment