2025-05-01 01:48:08 -07:00

2.2 KiB

Use an Addressable asset

To load and use an Addressable asset, you can:

Refer to Loading assets for more detailed information about loading Addressable assets.

Loading Addressable assets uses asynchronous operations. Refer to Operations for information about the different ways to approach asynchronous programming in Unity scripts.

Tip

You can find more involved examples of how to use Addressable assets in the Addressables Sample repository.

Use AssetReferences

To use an AssetReference, add an AssetReference field to a MonoBehaviour or ScriptableObject. After you create an object of that type, you can assign an asset to the field in your object's Inspector window.

Note

If you assign a non-Addressable asset to an AssetReference field, Unity automatically makes that asset Addressable and adds it to your default Addressables group. AssetReferences also let you use Addressable assets in a Scene that isn't itself Addressable.

Unity doesn't load or release the referenced asset automatically; you must load and release the asset using the Addressables API:

[!code-cssample]

Refer to Loading an AssetReference for additional information about loading AssetReferences.

Load by address

You can use the address string to load an asset:

[!code-cssample]

Remember that every time you load an asset, you must also release it.

Refer to Loading a single asset for more information.

Load by label

You can load sets of assets that have the same label in one operation:

[!code-cssample]

See Loading multiple assets for more information.