Unity Development — The Resources Folder
It is completely fine (and maybe beneficial) to avoid using the Resources folder in Unity, but it has its good points too.
Today’s Objective: Show how you can load game assets from the Resources project folder at runtime, and the benefits that gives.
Note: I haven’t used the Resources folder a lot, so at this point I am no where near an expert on its use. This post is meant as a brief introduction to the possibility of its use, and you should research it further before implementing it in a project.
What is the Resources folder in Unity?
The “Resources” folder is a special folder within the project files of a Unity project. The folder is not there by default, but can be created simply by creating a new folder inside the “Assets” folder and naming it “Resources” (The name is the important part).
The Assets and Objects in all folders named “Resources” are combined into a single serialized file when a project is built. This file also contains metadata and indexing information, similar to an AssetBundle.
[The Resources folder is…] the system that allows developers to store Assets within one or more folders named Resources and to load or unload Objects from those Assets at runtime using the Resources API. — Unity Source
A more in-depth implementation could be like this:
Best Practices for the Resources System:
[Quoted from Unity Source]
Don’t use it.
This strong recommendation is made for several reasons:
- Use of the Resources folder makes fine-grained memory management more difficult.
- Improper use of Resources folders will increase application startup time and the length of builds.
- As the number of Resources folders increases, management of the Assets within those folders becomes very difficult
- The Resources system degrades a project’s ability to deliver custom content to specific platforms and eliminates the possibility of incremental content upgrades.
- AssetBundle Variants are Unity’s primary tool for adjusting content on a per-device basis.
Proper uses of the Resources system:
[Quoted from Unity Source]
There are two specific use cases where the Resources system can be helpful without impeding good development practices:
- The ease of the Resources folder makes it an excellent system to rapidly prototype. However, when a project moves into full production, the use of the Resources folder should be eliminated.
- The Resources folder may be useful in some trivial cases, if the content is:
- Generally required throughout a project’s lifetime,
- Not memory-intensive,
- Not prone to patching, or does not vary across platforms or devices,
- Or used for minimal bootstrapping.
This is only a brief intro into the use of the Resources folder, and I have not covered many parts/factors of its use. If you wish to learn more, please do more of your own research to determine if the Resources folder is suitable for your project/s.
Best of luck to you!