Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


DeferInitialization

Whether the system waits for an explicit call to LocalizationSettings.InitializeAsync before it initializes.
Read time 2 minutesLast updated 6 days ago

Definition

  • Type: Property
  • Namespace: Unity.Localization
  • Assembly: UnityEngine.LocalizationRuntimeModule
public bool DeferInitialization { get; }

Remarks

Off by default, so the first value resolved starts initialization. Turn it on, through Project Settings > Localization, when the startup locale depends on something that loads first, such as a save file or a platform sign-in. Call LocalizationSettings.InitializeAsync once the data is ready; it lifts the block for the rest of the session. While it is on, an awaited read simply waits and resolves once initialization runs. A synchronous read cannot wait, so it throws instead, and the stack trace names what asked too early. Nothing starts the run but you, which is the point: the alternative is loading the wrong language and reloading every table. Note that an awaited read never completes if initialization is never asked for. This applies to players and to Play Mode only. In the Editor outside Play Mode the system still initializes on demand, so the table windows and inspectors keep working with no game running to ask for a value.
Initialize localization only once a save file has loaded.

Examples

using Unity.Localization;using UnityEngine;namespace Unity.Localization.Samples{ // Requires Defer Initialization in Project Settings > Localization, so nothing resolves a value before this runs. public class DeferInitializationExample : MonoBehaviour { async void Start() { var saved = await LoadSaveFileAsync(); var settings = LocalizationSettings.Instance; if (settings != null && !string.IsNullOrEmpty(saved)) settings.StartupSelectors.Insert(0, new SpecificLocaleSelector { LocaleId = saved }); await LocalizationSettings.InitializeAsync(); Debug.Log($"Started in {LocalizationSettings.SelectedLocale?.LocaleName}"); } static async Awaitable<string> LoadSaveFileAsync() { await Awaitable.NextFrameAsync(); return "de"; } }}