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

LocalizationSettings.PreferredLoading

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

public static LoadingPreference PreferredLoading;

Description

The default loading behaviour used by the reference accessors and their change events.

Defaults to LoadingPreference.Asynchronous. When set to LoadingPreference.Synchronous, the event-driven accessors (LocalizedString.GetLocalizedStringAsync, LocalizedAsset<T0>.GetLocalizedAssetAsync, and LocalizedTable.GetTableAsync) resolve synchronously when the value is available, and fall back to an asynchronous load when it is not. When no settings instance is registered, this reads as LoadingPreference.Asynchronous.

Additional resources: LoadingPreference

<para>Make localized references resolve synchronously by default.</para>

using Unity.Localization;
using UnityEngine;

namespace Unity.Localization.Samples { public class PreferredLoadingExample : MonoBehaviour { [SerializeField] LocalizedString m_Greeting = new();

void OnEnable() { LocalizationSettings.PreferredLoading = LoadingPreference.Synchronous; m_Greeting.StringChanged += OnGreetingChanged; }

void OnDisable() => m_Greeting.StringChanged -= OnGreetingChanged;

void OnGreetingChanged(string value) => Debug.Log(value); } }