Search Unity

BaseHierarchySort no longer supported?

Discussion in 'Scripting' started by StarManta, Jul 26, 2017.

  1. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    When I try to create a new class to sort object in the hierarchy, I now get the following warning:
    Code (csharp):
    1. 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?
     
  2. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    If they are objects, use Linq.

    Code (csharp):
    1.  
    2. var sort = objects.OrderBy(o => o.Name).ToList();
    3.  
     
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    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.
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,297
  5. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    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.