- Home /
hierarchy is not in order
I just downloaded the new update (4.5.0f6) and now my hierarchy window is messed up. It seems to be that everything that is not a prefab (white letters) is sorted correctly but everything that is a prefab (blue letters) is not sorted at all. I have tried reloading the scene, loading a different scene, restarting Unity, and restarting my computer but nothing has helped. Before the update everything was working fine, but now it is just an unorganized mess.
Is this a bug with the update? or did I do something that caused this?
Thanks.
It's a long awaited feature to allow reordering based on transform. Note that order within the editor in the older versions was not guaranteed to be the same (nor was it usually) when you run the stand alone version. I'm hoping with this latest feature, the order will be consistent across devices as well, haven't tried that though, but most of my code doesn't rely on ordering due to the legacy operation. That would make some UI utilities easier to use because you won't have to state an explicit order necessarily and can rely on the Transform child order. It will take some getting used to though, because I've adapted (probably like yourself) to seeing everything in alphabetical order.
All I want to do is find out how to order gameobjects at runtime but it seems that can't be done???
So how do you make one object go behind another and back again based on button presses? Have they made this impossible now???
Answer by karljj1 · May 29, 2014 at 06:27 PM
This is a new feature. You can now re order the structure of objects manually or write a script to make it alphabetical again if you wish.
http://unity3d.com/unity/whats-new/unity-4.5
New Hierarchy Window sorting - sorting of elements is now based on transform order instead of name.
Ah I see, thanks!
For those who have this same issue, here is a script.
using UnityEngine;
using UnityEditor;
public class AlphaNumericSort : BaseHierarchySort
{
public override int Compare(GameObject lhs, GameObject rhs)
{
if (lhs == rhs) return 0;
if (lhs == null) return -1;
if (rhs == null) return 1;
return EditorUtility.NaturalCompare(lhs.name, rhs.name);
}
}
when this compiles there will be a little icon next to the search bar on the hierarchy window, click that and you can switch between transform or alphabetical sort.
Its worth noting one of the reasons for this is so you can adjust the order that layers are drawn in the new GUI system by simply re-ordering their hierarchy.
Now, if I figure out how to force Shuriken particle sorting based on this, my life would be much better.
Answer by Calos1591 · Jul 24, 2016 at 06:20 AM
Enable Alpha Numeric Sorting
This is great, it actually adds an options box rather than just enabling it, so you can switch between the two as needed (on v2017.2). ][1]
Answer by IsaiahKelly · Jun 08, 2014 at 12:02 AM
Using that script to bring back the old hierarchy view will actually cause more problems down the road since it wont work with the new uGUI system coming to Unity 4.6. So it's not recommended.
However, I did create a tool over here to allow users to easily reorganize their hierarchy since the 4.5 update that doesn't require the old system at all.
Answer by 8bitgoose · May 26, 2015 at 09:56 PM
This script will allow you to sort one level of child objects in the hierarchy. Helpful when you need to sort objects that hold lots of similarly named prefabs.
NOTE: it is a crappy bubble sort that isn't efficient. But it did organize about a hundred items in 87 milliseconds. You won't notice it when you need it.
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;
public class SortChildObjects : EditorWindow {
[MenuItem("GameObject/Sort By Name",false,-1)]
public static void SortGameObjectsByName(MenuCommand menuCommand)
{
if(menuCommand.context == null || menuCommand.context.GetType() != typeof(GameObject))
{
EditorUtility.DisplayDialog("Error", "You must select an item to sort in the frame", "Okay");
return;
}
GameObject parentObject = (GameObject)menuCommand.context;
if(parentObject.GetComponentInChildren<Image>())
{
EditorUtility.DisplayDialog("Error", "You are trying to sort a GUI element. This will screw up EVERYTHING, do not do", "Okay");
return;
}
// Build a list of all the Transforms in this player's hierarchy
Transform[] objectTransforms = new Transform[parentObject.transform.childCount];
for(int i = 0; i < objectTransforms.Length; i++)
objectTransforms[i] = parentObject.transform.GetChild(i);
int sortTime = System.Environment.TickCount;
bool sorted = false;
// Perform a bubble sort on the objects
while(sorted == false)
{
sorted = true;
for(int i = 0; i < objectTransforms.Length - 1; i++)
{
// Compare the two strings to see which is sooner
int comparison = objectTransforms[i].name.CompareTo(objectTransforms[i+1].name);
if( comparison > 0) // 1 means that the current value is larger than the last value
{
objectTransforms[i].transform.SetSiblingIndex(objectTransforms[i + 1].GetSiblingIndex());
sorted = false;
}
}
// resort the list to get the new layout
for(int i = 0; i < objectTransforms.Length; i++)
objectTransforms[i] = parentObject.transform.GetChild(i);
}
Debug.Log("Sort took " + (System.Environment.TickCount - sortTime) + " milliseconds");
}
}
Your answer
Follow this Question
Related Questions
Highlighting / Focusing on an Editor Window Through Code 1 Answer
The best way to sort list of gameobjects in order I need? 0 Answers
How does one access the Hierarchy Window? 2 Answers
Making a glass/window shader with cubemap reflection and transparency options 2 Answers
Some questions about Gui.Window 1 Answer