Heya, I am currently decorating my scene with various objects in Unity, but the Hierarchy is getting extremely cluttered, is there a way to create folders there to put environment objects in to keep it all tidy?
I am making a TDG so when the game is played the towers that get created clutter up the Hierarchy as well. So if there is any way to make a group, folder or anything that will not spam the Hierarchy, so do not have to scroll for 2 minutes to find 1 particular object
Hereâs a little Unity editor script I use to group selected objects. Just save this as Assets/Editor/GroupCommand.cs. Use âCtrl-Gâ or âGameObject Menu > Group Selectedâ. It also supports Undo:
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;
}
}
Yes there is, but they arenât really folders. If you go to GameObject > Create Empty this will place an empty object on your scene as well as your Hierarchy, you can then drag particular objects into that without affecting your game at all.
Example:
You have a butt load of lights in your scene. You can then create a Game Empty and call it âLightsâ and then drag in all your lights into the object.
Actually a âemptyâ gameobject still has a transform (cant be removed), which means that any normal logic that works via âtransform.rootâ will break. Given the complex child/component relation unity uses, i would not advice to use this âhackâ to simulate folders/grouping.
Often its to complicated to sort out what child may or may not have a certain component, so its common practice to search from the transform.root, which in the case of those âfolderâ objects will result in wrong or unpredictable behavior.
Create an empty gameobject and reset itâs position to (0,0,0). Drag this the project folder to create a prefab. Whenever you need to group objects, drag this prefab into the scene and itâs position will remain at the origin. Just make sure not to press apply on any of the groups.
Make a little empty script called (for instance and understanding) âWorkScriptTagâ, that functions as, sort of, a Tag.
Find all your item that you want to âGroupâ in your (most likely/up-to wast structured) hierarchy, and mark them.
Now, while all marked blue, press âAdd componentâ, and add the âWorkScriptTagâ to all the items/gameobjects you want to group.
Go to âProjectâ and right click the script and press the menu object; âFind References in Sceneâ.
This will result in you being able to handle + being-able-to-select all the given hierarchy GameObjects with the pseudo-âTagâ above (aka the âWorkScriptTagâ script attached).