Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


TryLoadAsset<T>(AssetKey, out T)

Resolves the referenced asset for the key without an asynchronous load.
Read time 1 minuteLast updated 14 days ago

Definition

TryLoadAsset<T>(AssetKey, T)

public bool TryLoadAsset<T>(AssetKey key, out T asset) where T : Object

Parameters

The asset to resolve.

asset

T
The resolved asset, or
null
on a miss.

Returns

Type

Description

bool
true
when the asset resolved; otherwise
false
.

Remarks

Returns
true
and the asset when the address is registered and the asset is a
T
(or matches AssetKey.Type when
T
is the base Object); otherwise returns
false
with a
null
asset. Because the assets are already in memory, this provider only implements the synchronous capability.
Register a texture by address and resolve it back through the provider.

Examples

using Unity.Localization.Providers;using UnityEngine;namespace Unity.Localization.Samples{ public class ReferencedAssetProviderLoadAssetGenericExample { public void Run() { var provider = new ReferencedAssetProvider(); provider.Add("UI/Logo", new Texture2D(2, 2)); if (provider.TryLoadAsset<Texture2D>(new AssetKey("UI/Logo", typeof(Texture2D)), out var logo)) Debug.Log(logo.name); } }}