Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


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:

Add an asset entry

To add an asset entry to a collection:
  1. Open Window > Localization > Resource Tables and select the collection.
  2. Create a key and choose the asset entry type.
  3. Assign each locale's asset in its column.
Each asset entry stores its value in one of two ways:

Storage

Description

DirectThe 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.
ResourcesThe table stores a path into a
Resources
folder, and the asset loads on demand.
For a Resources entry, place the asset under a
Resources
folder yourself before assigning it. If the asset isn't under
Resources
, the entry can't store a path and the Unity Editor logs a warning.

Use the asset

Reference localized assets in your scripts by using a
LocalizedAsset<TObject>
field, or one of the built-in types:
LocalizedTexture
,
LocalizedSprite
,
LocalizedAudioClip
,
LocalizedFont
,
LocalizedMaterial
,
LocalizedGameObject
, or
LocalizedObject
.
Subscribe to
AssetChanged
to receive the asset when it resolves and again on every language change. To pull an asset on demand instead, call
GetLocalizedAsset
or its asynchronous counterpart
GetLocalizedAssetAsync
.
Note
Whether the synchronous call can succeed depends on the entry's storage and the content source. Direct references resolve synchronously. Other sources might only support asynchronous loading. Refer to Synchronous and asynchronous loading.

Localize without code

Add the component that matches the asset type, then wire its event to the property that displays the asset:
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
ReleaseAssets
on the database, or
ReleaseAllAssets
.

Additional resources