My game randomly freezes during LocalizedString.GetLocalizedString
. It’s probably a race-condition inside the Addressables code.
Unfortunately, it occurs in our production project only. I’m unable to reproduce it in a smaller test project. But I wanted to post it here nonetheless, perhaps you have an idea.
The very first code that’s executed in the game (added as first scene in ‘Scenes in Build’) just a light-weight loader scene and contains this code:
System.Collections.IEnumerator Start()
{
// control how long it takes to load data asynchronously vs performance impact on the game while loading in the background.
// at application startup and during the loading screen in general, we don't care for smooth framerate. We want the work to get done fast.
Application.backgroundLoadingPriority = ThreadPriority.High;
// Without initializing Addressables, the game sometimes hangs
yield return UnityEngine.AddressableAssets.Addressables.InitializeAsync();
// Load menu scene
yield return SceneManager.LoadSceneAsync(k_SceneToLoad);
Loading the scene sometimes triggers the freeze, because Components in that scene call LocalizedString.GetLocalizedString
.
The game is stuck here:
I added tons of yield’s to the code in a desperate attempt to workaround it. At first it looked like it would work, but you just have start the game often enough to run into the freeze again:
System.Collections.IEnumerator Start()
{
// control how long it takes to load data asynchronously vs performance impact on the game while loading in the background.
// at application startup and during the loading screen in general, we don't care for smooth framerate. We want the work to get done fast.
Application.backgroundLoadingPriority = ThreadPriority.High;
// Without initializing Addressables, the game sometimes hangs
yield return UnityEngine.AddressableAssets.Addressables.InitializeAsync();
yield return null; // without this the game sometimes hangs too (seems like a race condition in addressables)
// without this the game sometimes freezes (seems like a race condition in addressables)
yield return UnityEngine.Localization.Settings.LocalizationSettings.InitializationOperation;
yield return null; // not sure if this yield is necessary
yield return UnityEngine.Localization.Settings.LocalizationSettings.StringDatabase.PreloadOperation;
yield return null; // not sure if this yield is necessary
// Load menu scene
yield return SceneManager.LoadSceneAsync(k_SceneToLoad);
Adding yield return LocalizationSettings
slightly changed where the game is freezing. I also tried WaitForCompletion
, but same problem.