9th and 10th elements in project list get swapped if they have identical filenames

Maybe I’m becoming dumb but I can’t find if there’s some error on my part here.
More than testing by changing names, I don’t know what to do.
All works correctly before and after lines 9 and 10.
I only wonder how I didn’t ever notice this before.
9439802--1324133--upload_2023-10-30_12-15-27.png9439802--1324139--upload_2023-10-30_12-16-24.png9439802--1324142--upload_2023-10-30_12-17-14.png

9439802--1324136--upload_2023-10-30_12-16-6.png

It’s not even like this about rows 9 and 10.

9450281--1326692--upload_2023-11-4_20-4-21.png

Am I stupid and not seeing something blatant or is there something going on here?
This might be something stupid that I can’t see, or might be a harmless bug or it could be something that lies there harmless until it destroys your project.
Nobody interested?

Not really. To Unity’s internal connections, filenames are irrelevant.

Their order in the project browser is even less than irrelevant! :slight_smile:

Nothing about the filename and nothing about the asset type or even the asset itself connects anything.

EVERYTHING in Unity is connected via its internally-assigned GUID.

SCRIPTS OR ASSETS ARE MISSING OR BLANK

ALWAYS move all Unity assets by using the Unity Editor. Any other way risks disconnecting the GUID in the meta file from the original file, and this will result in all connections to that asset being broken.

Some info about Missing script warnings, broken prefabs, GUIDs, renaming GUIDs, etc:

https://discussions.unity.com/t/836322/2
https://discussions.unity.com/t/815173/7
https://discussions.unity.com/t/815173/9

EVERYTHING in Unity is connected to the above GUID, which is stored ONLY in the metafile, and hence why the metafiles ALWAYS MUST be source-controlled.

When Renaming: It is super-easy to inadvertently change the GUID by renaming outside of Unity. Don’t do that. Instead:

  • close Visual Studio (important!)
  • rename the file(s) in Unity
  • in Unity do Assets → Open C# Project to reopen Visual Studio
  • now rename the actual classes, and MAKE SURE THE FILE NAMES DO NOT CHANGE!

If you are NOT using source control while you do this, renaming files is an EXTREMELY dangerous process. Use source control at all times so that you can trivially revert if you miss a critical step and damage your project.

If I had to speculate on order, it might be how it lies on disk, how it was first serialized, how its metafile sorted into the internal database, etc. But either way, doesn’t really matter except to the OCD folks among us.

Thank you for the exhaustive reply, I always use Unity to do any file operation in the project, so to not lose any connection.

I’m still curious about this bug, which seems harmless, being clearly only related to how Unity sorts the list, at this point.

It’s only a bug if it violates a documented specification, or obviously otherwise causes a crash.

I don’t know of anywhere that says what order identical-named files will be presented in. :slight_smile:

For instance, every filesystem seems to sort things like this differently:

12
0123
123
1245
1 2 3
1 23
200
200abc
200 abc
200-123```

Annoying? Yeah. Bug? No.

Have you checked whether you notice this same sort order in your OS’s file system? I was recently getting annoyed that Unity’s Project view seemed to sort things in a silly way:

9450761--1326851--upload_2023-11-5_10-30-22.png

It seemed weird that folders and materials didn’t sort in the same order. But just as I was concluding it was a bug, I found that Windows sorts the files identically, because windows is sorting based on the file extension (and the “.” in it) being part of the file name.

9450761--1326854--upload_2023-11-5_10-31-35.png

In short, I think Unity’s just relying on the same order applied by your operating system’s file system. So, I’d go look on your disk and see whether your OS is also sorting things in this way, if you order the files by name.

This chunk of screenshot comes from a brand new project, I am absolutely sure that I did all file operations inside Unity.
I only copied the textures in the folder in Unity, I only had one material in there and duplicated it inside Unity.
There were only the source files, all the .meta were deleted.

9452051--1327184--upload_2023-11-6_4-24-34.png

And this is in Windows:

9452051--1327187--upload_2023-11-6_4-25-10.png

As you can see Windows is sorting everything correctly.

The technical term you’re looking for here is “the sort algorithm is unstable,” as opposed to “stable.” If the keys are the same, do they remain in the same order they were originally found in the list or not.

In your case, the keys are the same (the filenames) but they do not remain in the same order you expect. Interestingly enough, this could be due to the Unity sort algorithm itself, OR, the operating system returning the results of a wildcard file search in a stable ordering or not.

I see.
Would be really weird if Win would sort one way and give data another way though, but with MS everything is possible.