Version: Unity 6.7 Alpha (6000.7)
LanguageEnglish
  • C#

ReferencedAssetProvider.TryLoadAsset

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public bool TryLoadAsset(AssetKey key, out T asset);

Parameters

Parameter Description
key The asset to resolve.
asset The resolved asset, or null on a miss.

Returns

bool true when the asset resolved; otherwise false.

Description

Resolves the referenced asset for the key without an asynchronous load.

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.

<para>Register a texture by address and resolve it back through the provider.</para>

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); } } }