Is there any way to use Resources.Load with a file path from the root assets directory rather than a folder called Resources? Should I just put everything in a folder called Resources? I mean I could do just that, but would that cause any problems if I put everything except the Editor and Standard Assets folder in one big Resources folder?
During the player, there is no function to read assets directly from outside a Resources/ folder. Its not even possible, because if the asset is never linked and is not inside a Resources/ folder, it is completely removed from the build.
Within the Editor, just use AssetDatabase.LoadAssetAtPath()
You can move as much as you like into a Resources/ folder. You can also have subfolders within Resources/ folder and you can have a Resources/ folder within a subfolder.
Example:
Assets/Resources/basics.bytes
Assets/art/Resources/Sprites/mysprite.tga
Assets/code/Resources/sample.prefab
You can load these objects like this:
byte[] basics = Resources.Load<TextAsset>("basics").bytes;
Sprite mysprite = Resources.Load<Sprite>("Sprites/mysprite");
GameObject samplePrefab = Resources.Load<GameObject>("sample");
Two things to remember here:
- You need to specify the sub-folder when loading via
Resources.Load
- Everything that is inside a Resources folder will be added to the final build, so be sure to remove all test assets and garbage before shipping to reduce game build size. (That is also true for all “test-GameObject’s” that you leave in any scene that is shipped. Even if the GameObject is deactivated, all assets it references will be included in the build).
There is another option of dynamic resource loading: AssetBundles. Basically, you can pack any asset into an AssetBundle (from any folder) and later in the game load that bundle and then load things out of the AssetBundle in a similar syntax to Resources.Load
.