I understand that the resource folder allows you to access resources by name in your scripts and allows you load them more easily, but does it make anything faster or does it reduce instantiation memory problem?
On whole, does it have any advantages other than accessing it differently because I didn’t seem to find any in the documentation.
If you’re doing any procedural generation, there is no other option but to use the resources folder.
There is no downside to using the resources folder if you manage it correctly.
Now, this isn’t entirely true. You can load images and assets which are not in the resources folder if you have a custom image loader (there are a number of unity compatible ones, like the tga loader that work). However, since you can’t bundle files that aren’t in the project, this adds a lot of complications (eg. now you can’t use the web player, because you’re relying on a file based resource loading mechanism).
Also, using the resources folder increases project size, it’s true. However, this argument is a straw man. Obviously if you use an asset you’re going to increase the size of the project. The downside of the resources folder is that unused assets are always included in the build, and unity cannot smart-prune down to only assets that are actually assigned to objects.
…If you’re not an idiot (and I’d hope that most people here manage to fall into this category), and can manually manage these issues, there’s no tangible downside to using the resources folder.
You can use the resources folder to decrease build size if the images you’re using get larger when Unity3D converts them. You can see the original image size using your folder explorer and you can see the converted size in images preview window.
Doing this conversion on the device is a performance hit. It can be done by giving the images a .bytes extension then using:
var binImage = Resources.Load<TextAsset>(imagePathInResourcesFolder);
myTexture2D.LoadImage(binImage.bytes);
hi @Eric5h5, can you explain further how the resources in the Resources folder are all loaded into the memory? Some say that resources in the resources folder are included in the build but not included in the memory during runtime.
Yes, Unity omits certain resources, on each build, bu random, in my 1.2 GIG large project.
With web builds - always something missing from game, or not working properly,
In the windows builds - no such problem.
I believe that this whole story (and such problems) developpers DON’T NEED, and Unity
should fix this issue in the upcoming versions, in the way that:
-no matter where you keep your assets, or how messed up is your folders structure, Unity
should search everything on build time, and include only what is used in your build,
as FINAL.
It has no advantages, only disadvantages. Namely, all assets in Resources are loaded into memory from the beginning since there’s no good way to tell in which scenes they are used. Also, references are hard-coded in your scripts, so any housekeeping you do, such as moving and renaming, means you must remember to update your scripts or else they break. Finally, all items in Resources are included in a build whether you use them or not, since (similar to the first point), there’s no good way to tell otherwise.
Generally you should not use Resources, except for specific circumstances where it makes sense to access them through code. (Note that just having a lot of objects to drag into an array isn’t really a reason, since you can use the lock icon to lock the inspector, and drag many prefabs onto an array at once.) In most normal cases, drag’n’drop is easier and better since it avoids hard-coding and allows Unity to manage the assets intelligently.