Selection.GetFiltered sorting?

It looks like when I call Selection.GetFiltered with SelectionMode.DeepAssets, the results coming back are not sorted. I was hoping for a depth-first array of objects, but instead I’m getting everything in a totally random order. Since the return type is a builtin array, I was hoping for something simple to deal with.

Sorting after the fact is not my preference, as it means I’ll have to name all the leaf nodes with numbers ahead of time, where I wanted the parent folder names to be the first sort parameter. :frowning:

Anyone had any experience sorting Selection results?

OK, solved my own problem. :slight_smile: Here’s how:

		// Build the resource file from the active selection.
		Object[] selection = Selection.GetFiltered(typeof(Texture2D), SelectionMode.DeepAssets);
		
		string[] fullSelectionPaths = new string[selection.Length];
		for (int i=0; i<selection.Length; i++) {
			fullSelectionPaths[i] = AssetDatabase.GetAssetPath(selection[i]);
		}
		// Sort selection array by path keys
		System.Array.Sort(fullSelectionPaths, selection);