Localize assets
Swap textures, audio, and other assets per language.
Read time 2 minutesLast updated 17 days ago
Swap textures, audio, and other assets per language.
Asset entries in collection tables work like string entries, so they have one key and one asset per locale. Use them for anything visual or audible that changes with language, for example a texture containing text, a voice-over clip, or a font.
Prerequisites
Before you start, make sure you have the following:
- A table collection. Refer to Get started with localization.
- The assets you want to localize, one per locale for each key you'll add.
Add an asset entry
To add an asset entry to a collection:
- Open Window > Localization > Resource Tables and select the collection.
- Create a key and choose the asset entry type.
- Assign each locale's asset in its column.
Each asset entry stores its value in one of two ways:
Storage | Description |
|---|---|
| Direct | The table references the asset, and the asset loads when the table loads. This is the simplest option, but every referenced asset ships and loads with the table. |
| Resources | The table stores a path into a |
For a Resources entry, place the asset under a folder yourself before assigning it. If the asset isn't under , the entry can't store a path and the Unity Editor logs a warning.
ResourcesResourcesUse the asset
Reference localized assets in your scripts by using a field, or one of the built-in types: , , , , , , or .
LocalizedAsset<TObject>LocalizedTextureLocalizedSpriteLocalizedAudioClipLocalizedFontLocalizedMaterialLocalizedGameObjectLocalizedObjectSubscribe to to receive the asset when it resolves and again on every language change. To pull an asset on demand instead, call or its asynchronous counterpart .
AssetChangedGetLocalizedAssetGetLocalizedAssetAsyncLocalize without code
Add the component that matches the asset type, then wire its event to the property that displays the asset:
- Localize Texture Event ()
LocalizeTextureEvent - Localize Sprite Event ()
LocalizeSpriteEvent - Localize Audio Clip Event ()
LocalizeAudioClipEvent - Localize Game Object Event ()
LocalizeGameObjectEvent
For other asset types, create a custom component type and derive from .
LocalizeAssetEvent<TObject>Release loaded assets
The database caches loaded assets per locale. To free them, for example after you leave a scene, call on the database, or .
ReleaseAssetsReleaseAllAssets