How do you get a localized Sprite from AssetTableEntry?

Example for getting a localized string:

StringTableEntry tableEntry = currentStringTable[localizationID];
string localizedString = tableEntry.GetLocalizedString(LocalizationSettings.SelectedLocale.Formatter);

How do we get a localized Sprite?

I tried to use the same style but instead of StringTableEntry I tried to use AssetTableEntry.
How do you get the localized sprite from AssetTableEntry?

Thanks!

Oh yes we don’t have a method inside the entry here.
The simplest way is to just use the AssetDatabase.
LocalizationSettings.AssetDatabase.GetLocalizedAsset<Texture>("My Table", "My Entry:);

You can also get the asset from the AssetTable using GetAssetAsync.

Ill create a task to add support directly to the entry for the future.

Also for the string you don’t need to pass in the formatter, it will use the SelectedLocale formatter by default.

1 Like

Thanks!

public IEnumerator SetLocalizedSprite(string localizationID, SpriteRenderer spriteRenderer)
{
AsyncOperationHandle spriteAsyncOp = currentAssetTable.GetAssetAsync((TableEntryReference)localizationID);
yield return spriteAsyncOp;
spriteRenderer.sprite = spriteAsyncOp.Result;
}

1 Like

One more question I have is if I should be holding on to a reference of the AsyncOperationHandle while that Asset is in use?

Thats fine to do but if you do plan to hold a reference then you should use Addressables.ResourceManager.Aquire so that it does not get unloaded and Release when you have finished holding on to the reference. Otherwise, the value may suddenly go null on you at some point when all references are released.