It's a common practice in Unity to start the name of a scene, prefab, etc. with an underscore so it will be listed first in the project window.

This is because things are sorted lexicographically and underscores come before letters in ASCII, right?

Well, no.

asciitable.com/

So what the heck is Unity using to sort things? Did they ... did they really add the underscore as a special case?

@peterdrake Unity’s project browser uses a custom function called EditorUtility.NaturalCompare() which tries to do “human like” sorting. I’d tell you more but the implementation is on the native side 🙃

Follow

@thebeardphantom The documentation gives absolutely no hint as to this behavior, but points out another shocking decision.

docs.unity3d.com/ScriptReferen

Not sure how one would run across this documentation without knowing the name.

@peterdrake By shocking decision you mean how it mentions how numbers are sorted?

@thebeardphantom Yes. Lexicographic is a single, easy-to-understand rule. Stacking up a bunch of special cases (especially if undocumented) is a path to unpleasant surprises.

@peterdrake I think the idea is to mimic how file browsers in OS’s sort based on similar rules. Windows will sort filenames using special rules for numbers. It also sorts underscores in the same way.

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.