- Home /
Is using the resource folder worth it?
Hey,
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.
Answer by doug__ · Jan 31, 2013 at 03:02 AM
Yes.
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.
I agree with all your points. People shouldn't put assets into the resources folder they aren't using, although this becomes harder to manage for larger games and $$anonymous$$ms. It then becomes the responsibility of the developers to keep the resources folder clean.
Hi All,
Is there a solution for our situation where we want to use Resources for development in Editor but asset bundles for beta testing and final release? Specifically: if I create asset bundles out of all the assets in our Resources folders, does Unity know to prune them from the build?
Answer by ShawnFeatherly · Jun 02, 2015 at 10:52 PM
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);
source: http://answers.unity3d.com/questions/734863/sprites-compression-question-their-size-in-build.html
Answer by OZAV · May 23, 2014 at 10:26 AM
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.
@A0101A if you P$$anonymous$$ me the bug number for this issue, I'll get someone to investigate for you. If your project is too large to upload let me know and I'll find a server you can push it to. I'm sure that Unity doesn't randomly leave assets behind when making a build. The build process does traverse all assets and script looking to see what's used by the game.
Answer by Eric5h5 · Feb 16, 2012 at 09:40 PM
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.
+1
It was also a big headache for me when I transitioned to using Asset Bundles.
That being said it is convenient to use the Resources folder temporarily when I'm testing new assets that will be included in an Asset Bundle later but I don't want to rebuild the bundle every time I make a change.
I can't downvote, but the part where you say that stuff in Resources is loaded into memory is WRONG. Stuff in resources does get included in the build, but not automatically loaded into memory.
I will not down-vote your answer but you should correct the part where you say that "all assets in Resources are loaded into memory from the beginning" as it is completely NOT TRUE and misleading to someone that could benefit from loading resources dynamically.
I realise this is an old question/answer but it is also the first to popup in a google search related to this so you need to fix the answer. This statement in the documentation is saying something different from what you are saying.
"Unity supports Resource Folders in the project to allow content to be supplied in the main game file yet not be loaded until requested"
http://docs.unity3d.com/Documentation/$$anonymous$$anual/LoadingResourcesatRuntime.html
I've never disagreed with one of @Eric5h5's answers before (never had need to!) but this just popped up from a Google search for me while doing some optimisation, and I feel it really needs to be corrected/clarified.
The problem with assigning prefab references in the inspector is that they are entirely loaded into memory at runtime - whether the prefab is ever actually instantiated in the scene or not. The advantage of using prefab references is that unused assets are stripped from the build.
Using Resources.Load is the reverse: every asset in the /Resources folder is included in a build, but they are only allocated any memory when you call Resources.Load.
Your answer
Follow this Question
Related Questions
Loading image for inventory from calculated path 0 Answers
Load a list of scripts from folder 1 Answer
Inside Resources folder vs outside 1 Answer
how Load Prefabs after build 0 Answers
Dynamic Material & Textures 1 Answer