When using Resource.Load, it’s possible to specify the type wanted.
Prefabs and Models both seem to be treated as GameObjects.
If you have both a prefab and a model with the same name and path, it seems one or the other gets loaded seemingly at random.
Is this expected behaviour?
I know the solution is “just don’t name them the same” but I’m interested in:
- why this behaviour is allowed in the first place
- why might it be a good idea?
- what naming conventions do people use to differentiate between models and prefabs?
Yes you can specify the type quite easily:
//Loads the model
Resources.Load("Name", typeof(Mesh)) as Mesh;
//Loads the prefab
Resources.Load("Name", typeof(GameObject)) as GameObject;
The random loading without the type is intended behavior, it will load the first file it finds with the correct name and you have no guarantee of which order those files are in. I usually always load by type just to be sure.
To answer your bullet points:
- It is allowed because the file system itself allows different file types to have the same file name.
- I do not recommend having two files named the same in the same folder, so personally I don’t think it is a good idea.
- I often name them the same but put them in their own folders instead. You then load it with resources like this: Resources.Load(“Models/Name”);