Resources.Load<T>("Path") vs. Resources.LoadAll<T>("Path")

I have a resources folder with one prefab in it.

PrefabType p = Resources.Load(“pathToPrefab”) returns null

PrefabType[ ] p = Resources.LoadAll(“pathToPrefab”) returns an array of length 1 with the correct object.

Sorry to be like WTF, but WTF. Okay, not sorry at all. I tested this multiple times. The loadall version actually finds the object in the folder. The load version does not.

Could someone explain this to me, because I am clueless.

Thanks,

Is it perhaps so that your “pathToPrefab” points to a folder? LoadAll will load all within a folder, but Load have to be the direct path to an asset.

This works:
GameObject carObj = Resources.Load(“Prefabs/Cars/Car”) as GameObject;

This also works:
GameObject [ ] carObjs = Resources.LoadAll(“Prefabs/Cars”) as GameObject;

This doesn’t work:
GameObject carObj = Resources.Load(“Prefabs/Cars”) as GameObject;

1 Like

Well that makes perfect sense. Maybe with this knowledge, I’ll go back and re-read the documentation and see if it’s telling me this.

Thank you for the very informative answer with clear examples, just what I was looking for.

1 Like