Skip to content

Instantly share code, notes, and snippets.

@raisilhamn
Last active November 16, 2023 11:39

Revisions

  1. raisilhamn revised this gist Nov 30, 2021. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions GroupCommand.md
    Original file line number Diff line number Diff line change
    @@ -18,5 +18,7 @@ public static class GroupCommand
    }
    ```
    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
  2. raisilhamn created this gist Nov 30, 2021.
    22 changes: 22 additions & 0 deletions GroupCommand.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    Not my script. Just personal note
    ```cs
    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