Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


LoadAssetAsync<T>(AssetKey, CancellationToken)

Loads the asset for the key from a Resources folder as the requested type.
Read time 1 minuteLast updated 13 days ago

Definition

public Awaitable<T> LoadAssetAsync<T>(AssetKey key, CancellationToken cancellationToken) where T : Object

Parameters

The asset to load.

cancellationToken

A token that cancels the load.

Returns

Type

Description

Awaitable<T>The loaded asset, or
null
when nothing at the path matches.

Remarks

Resolves the address through any registered alias, then loads it from
Resources
as
T
, or as AssetKey.Type when
T
is the base Object. When AssetKey.SubAssetName is set, the named sub-asset at the path is returned. Completes with
null
when nothing at the path matches, and throws OperationCanceledException when the load is cancelled.
Load a sprite from a Resources folder.

Examples

using System.Threading;using Unity.Localization.Providers;using UnityEngine;namespace Unity.Localization.Samples{ public class ResourceFolderProviderLoadAssetGenericExample { public async Awaitable Run() { var provider = new ResourceFolderProvider(); var icon = await provider.LoadAssetAsync<Sprite>( new AssetKey("UI/Icons/Settings", typeof(Sprite)), CancellationToken.None); if (icon != null) Debug.Log(icon.name); } }}