BaseHierarchySort no longer supported?

When I try to create a new class to sort object in the hierarchy, I now get the following warning:

Assets/Scripts/AppisodeComponents/Actions/RenderedActions/Editor/SortHierarchyBytime.cs(6,36): warning CS0618: `UnityEditor.BaseHierarchySort' is obsolete: `BaseHierarchySort is no longer supported because of performance reasons'

I need to be able to sort root-level objects by a specific value on one of their components, and, if I’m reading this correctly, that seems to now be impossible in Unity? What “performance reasons” justify removing the feature entirely? Is there a new way to implement such a feature?

If they are objects, use Linq.

var sort = objects.OrderBy(o => o.Name).ToList();

I think you may have misunderstood what I’m looking for.

I’m not trying to sort a list of object that I have in script. I’m trying to sort the Hierarchy view in the editor.

There is no custom sorting now, as stated it had to be removed for performance reasons as we do all our sorting in an optimized manner in C++ now. If you want to do come custom sorting you could use the sibling index value to change the order.

I have to say, that’s extremely disappointing - and setting sibling index is not a viable substitute in all cases, especially when collaborating (when multiple teammates prefer different sort orders for their own purposes, for example, including some that prefer to keep the order they put them in!). It would be even more unworkable if I were to need a custom sort within a GUI, since the sibling index has an actual gameplay implication in that case. I consider this a fairly serious feature regression.

I’m also surprised to hear there were performance implications to any degree that mattered - I used a custom sort on a game with hundreds of objects being sorted this way, and profiled this game quite a lot, and never had issues.

May I make a recommendation on this point which should avoid compromising performance - add a second sibling index (call it maybe .hierarchySortingIndex for example) which has no direct gameplay implications and is meant to be used solely for hierarchy window sorting. If it’s at its default value (such as -1) the window uses sibling index to determine the order; if not, it uses the new value.

5 Likes