Managing assets at runtime
Use the Resources system to load assets at runtime
Introduction to runtime asset managementUnity provides the following ways to load and manage the assets in your project at runtime:
Resources
API to load and unload assets originating from the Resources
folders in your project.AssetBundle
API to organize assets into AssetBundles which you can store remotely and download on demand.AssetBundle
API, it automates a lot of the manual processes that the AssetBundle system has, and provides a Unity Editor interface.Direct reference asset management is the default way of managing assets at runtime in Unity. Whenever you drag an asset into a scene or onto a component through the InspectorA Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info
See in Glossary window of the Editor, you create a direct reference to that asset. When you build your application, Unity saves any referenced assets in a separate file associated with the scenes in your project.
When your application runs on the target device, Unity loads the entire asset file into memory before loading a scene. This approach isnât dynamic and you can only load or unload a scene. If your project only uses direct references to load assets, then it can lead to slow load times, especially on devices with less memory.
Resources systemThe Resources system provides a simple way of managing assets in memory. To use the Resources system, you create a folder called Resources
in your project and add assets to it. During the build process, Unity finds the assets in the Resources
folder and bundles them into a serialized file with metadata and indexing information. You can then use the Resources
API to load and unload the assets in your application.
The Resources system has the following limitations:
Resources
folders are always included in the player build, even if theyâre not referenced by anything.Resources
folder, then building and starting your application can take a long time.Itâs an ideal system for prototyping, or for smaller projects which need assets throughout the lifetime of the application. For more information, refer to Use AssetBundles to load assets at runtime.
AssetBundle systemUse the AssetBundle system to organize assets into separate container files called AssetBundles. You can store AssetBundle files in your project files, or remotely in the cloud.
The AssetBundle
API minimizes the impact on network and system resources by allowing you to download AssetBundles on demand. You can use this on-demand behavior to add DLC and post-release content updates to your application. For example, you can deliver new content for your game without requiring users to download a new version of your game. The AssetBundle
API then provides a way to load and unload assets from downloaded bundles.
The AssetBundle system has the following limitations:
AssetBundle
API doesnât keep track of asset dependencies. For example, if you want to load a prefabAn 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 infoAssetBundle
API isnât aware of whether an AssetBundle is hosted locally or remotely, so you need to keep track of the location of all the AssetBundles in your project.For more information, refer to Introduction to AssetBundles.
Addressables packageThe Addressables package provides a user interface in the Unity Editor to manage and organize the assets in your project. Itâs built on top of the AssetBundle
API and automatically manages dependencies, asset locations, and memory allocation, which you otherwise have to handle manually in the AssetBundle system. The Addressables package aims to remove the limitations of the Resources and AssetBundle system to make it easier to manage assets on demand.
Once you have made an asset Addressable, you can reference it by address in your code, rather than by its file name or AssetBundle location, which means you can change the location of an asset without needing to rewrite any code. For more information, refer to Addressables overview
ECS content management systemThe Entities package has its own content management system, where you use weak references to assets to load them at runtime. You can also create content archives to deliver content to an application. For more information, refer to Introduction to content management.
Additional resourcesManaging assets at runtime
Use the Resources system to load assets at runtime
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