Since you can have multiple Resources folders in your project, I’m wondering how Unity would know the difference between two assets that have the same relative path.
Could I know which file it will load? It doesn’t seem to be random since it’s loading the same file each time.
Could I force it to load the other file instead?
I don’t know how it works internally, most of us won’t, because that is done all on the unmanaged side and is only available to be seen by those who have source code licenses (or work for Unity).
I will say that Resources.Load will select the first one that it finds with a matching name. If you specify the type it’ll be the first one of that type it finds that matches that name. If two assets have the same name and type, then it’s the first again. It’s always the first.
The order of the assets though that would make which ‘first’ is unknown.
Don’t have 2 assets of the same name/path and type!
While the engine does support it I’ve generally found it to be a bad idea to have multiple Resources folders Just feels like setting myself up for obscure failure.
I sort of see different resources folders as an option for 3rd party plugin creators to include resources with out having to tell the user to put certain files into their root Resources folder. But to still have some unique folder in it to id themselves.
Yes I agree with you guys, it’s just that I’ve seen code where someone would use multiple Resource folders together with LoadAll, which runs fine then.
But multiple folders with single Load is indeed doomed to fail at one point.
You’ll be getting resources included in your build that you want be loading (the 2nd, 3rd, 4th of the same name and type). That doesn’t sound cheap to me.
No, what I mean is that I did something a bit similar in an old XNA project, where it would load from the base resources only if there was not the same name in an other folder.
What it allows is for a pretty easy way to override textures, dialogues or models by the final user by simply putting a file in a folder and not having to worry about getting/making an actual mod for the game.
I’m pretty new to Unity, but that question made me remember what I did back a few years ago as a student.
Correct. If you have two (or more) assets with the same name, then you need to write some runtime code that can work out which one you want to use. So, to use the example in the OP, you might need a first line of your file.txt that helps you work out which asset has been found. And, I think, using LoadAll is probably the only way you can get all of them anyway.
That’d work if you had access to the individual files post-build, which you don’t. So any folks doing the overriding would have to have Unity and download your full project anyway.