Use the Resources system to load assets at runtime
Load and unload assets with the Resources system
Introduction to the Resources systemThe Resources
class allows you to find and access objects that are in Resources
folders in your project.
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 a significant performance impact on your project, especially if it contains a large amount of assets. The AssetBundles system, or the Addressables package provide a better way of managing complex sets of assets. For more information on the different asset management options, refer to Introduction to asset management.
Using the Resources systemThe 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.
Itâs best practice to avoid putting a lot of content into 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 objects referenced from assets in the Resources
folder into a single serialized file when you build a project, similar to building one large AssetBundle. Unity takes time to construct the data structures that index all the objects in the file, and uses memory proportional to the number of objects, even if they arenât loaded. This has an impact on performance if the number of individual assets in Resource folders are large, or if there are prefabs that contain a lot of objects. For example, initializing a Resources system containing 10 thousand assets takes several seconds on low-end mobile devices, even though most of the objects contained in Resources folders are rarely needed in an applicationâs first scene.
Use the Resources system to load assets at runtime
Load and unload assets with the Resources system
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4