The Resources
class allows you to find and access objects that are in a Resources
folder in your project.
Important: The Resources system is a performance-intensive way to organize assets in your project and isn’t recommended. Use AssetBundles and the Addressables package instead.
You can use the Resources system to make an asset available to a project without loading it in as part of a sceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary. When you add content to a folder named Resources
in your project, Unity makes it available to load when needed, independent of the scenes that you build. However, having the content constantly available at runtime has significant performance impact on your project.
It’s best practice not to use the Resources
system for the following reasons:
Resources
folder slows down application startup and the length of builds.Resources
system makes it harder to deliver custom content to specific platforms and prevents incremental content upgrades.Resources
folder requires a player rebuild and redeployment, whereas AssetBundles are better suited for incremental content updates.AssetBundles and the Addressables package are the recommended alternative.
Unity combines all assets and objects in the Resources
folder into a single serialized file when you build a project. This file contains metadata and indexing information, which includes a serialized lookup tree that Unity uses to resolve a given object’s name into its appropriate File GUID and Local ID. It’s also used to locate the object at a specific byte offset in the serialized file’s body.
On most platforms, the lookup data structure is a balanced search tree, which has a construction time that causes the index’s loading time to grow more-than-linearly as the number of objects in Resources
folders increases.
This operation is unskippable and happens at application startup time while the initial non-interactive splash screen is displayed. For example, initializing a Resources
system containing 10,000 assets takes several seconds on low-end mobile devices, even though most of the objects contained in Resources
folders are rarely needed to load into an application’s first scene.
The Resources
system can be helpful in the following situations:
Resources
folder when a project moves into full production.Examples of the latter include MonoBehaviour singletons used to host prefabsAn asset type that allows you to store a GameObject complete with components and properties. The prefab acts as a template from which you can create new object instances in the scene. More info
See in Glossary, or ScriptableObject instances containing third-party configuration data, such as a Facebook App ID.
To use the Resources system:
Resources
in your project, and add assets to it. Unity then makes these assets available even if they’re not directly referenced in a scene. Note: You can have multiple Resources
folders located at different subfolders within your Assets
folder, and packages can also contain Resources
foldersResources.Load
in your code. Only assets in the Resources
folder can be accessed in this way.Unity stores all assets in the Resources
folders and their dependencies in a file in the build output called resources.assets
. If a scene in the build references an asset Unity serializes that asset into a sharedAssets*.assets
file instead.
Additional assets might end up in the resources.assets
file if they’re dependencies. For example, a material in the Resources
folder might reference a texture outside of the Resources
folder. In that case the texture is also included in the resources.assets
file, but isn’t available to load directly.
If you want to destroy scene objects that were loaded using Resources.Load
before loading another scene, call Object.Destroy
on them. To release assets and reclaim memory, use Resources.UnloadUnusedAssets
.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.