Search Unity

Resolved Error Message During RunTime After Localizing TMP GameObjects

Discussion in 'Localization Tools' started by mrmagic2024, Jan 17, 2024.

  1. mrmagic2024

    mrmagic2024

    Joined:
    Jan 6, 2024
    Posts:
    5
    Hey guys I might be doing something wrong here, but this is my problem:
    Recently I imported localization tools to my project, and I followed the official guides to set it up. There are no functionality errors, but I realised that every time I add a new TextMeshPro GameObject and track changes using Localization Scene Controls, I get one more error message in the Console as soon as I run the game:

    InvalidOperationException: Trying to release an object that has already been released to the pool.
    UnityEngine.Pool.ObjectPool`1[T].Release (T element) (at /Users/bokken/build/output/unity/unity/Runtime/Export/ObjectPool/ObjectPools.cs:118)
    UnityEngine.Pool.GenericPool`1[T].Release (T toRelease) (at /Users/bokken/build/output/unity/unity/Runtime/Export/ObjectPool/GenericPool.cs:30)
    UnityEngine.Localization.Operations.GetLocalizedStringOperation.Destroy () (at ./Library/PackageCache/com.unity.localization@1.4.5/Runtime/Operations/GetLocalizedStringOperation.cs:88)
    UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject].DecrementReferenceCount () (at ./Library/PackageCache/com.unity.addressables@1.21.19/Runtime/ResourceManager/AsyncOperations/AsyncOperationBase.cs:231)
    UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject].UnityEngine.ResourceManagement.AsyncOperations.IAsyncOperation.DecrementReferenceCount () (at ./Library/PackageCache/com.unity.addressables@1.21.19/Runtime/ResourceManager/AsyncOperations/AsyncOperationBase.cs:592)
    UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle.Release () (at ./Library/PackageCache/com.unity.addressables@1.21.19/Runtime/ResourceManager/AsyncOperations/AsyncOperationHandle.cs:532)
    UnityEngine.ResourceManagement.ResourceManager.Release (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle handle) (at ./Library/PackageCache/com.unity.addressables@1.21.19/Runtime/ResourceManager/ResourceManager.cs:715)
    UnityEngine.AddressableAssets.AddressablesImpl.Release (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle handle) (at ./Library/PackageCache/com.unity.addressables@1.21.19/Runtime/AddressablesImpl.cs:835)
    UnityEngine.AddressableAssets.Addressables.Release (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle handle) (at ./Library/PackageCache/com.unity.addressables@1.21.19/Runtime/Addressables.cs:1445)
    UnityEngine.Localization.AddressablesInterface.ReleaseInternal (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle handle) (at ./Library/PackageCache/com.unity.localization@1.4.5/Runtime/Addressables/AddressablesInterface.cs:82)
    UnityEngine.Localization.AddressablesInterface.SafeRelease (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle handle) (at ./Library/PackageCache/com.unity.localization@1.4.5/Runtime/Addressables/AddressablesInterface.cs:47)
    UnityEngine.Localization.LocalizationBehaviour.LateUpdate () (at ./Library/PackageCache/com.unity.localization@1.4.5/Runtime/Utilities/LocalizationBehaviour.cs:32)

    Solutions I've Tried:
    1. Run the Addressables Analyzer - didn't help
    2. Deactivate all TMP GameObjects associated with localization configs - no more error message
    3. Pre-load this scene in another scene without localization implementation - didn't help

    Also, I didn't call the Pooling API anywhere in my scripts.
    Thanks for anyone who might offer some help!! I'll be happy to provide any additional details if needed.
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,281
    Hi,
    Could you try updating to 1.5.0? It may not be visible in the package manager, try using the add from git option and type com.unity.localization
     
  3. mrmagic2024

    mrmagic2024

    Joined:
    Jan 6, 2024
    Posts:
    5
    I tried to do as you said, but the version was still 1.4.5 (I also tried removing the asset and reinstalling it using URL).

    By the way, I've also encountered a second issue:
    I made a button that changes the locale to the next on the list every time you press it. I currently have two locales configured, and the first two times I press the button (at runtime) it throws an error message (the "Locale:" part differs according to the next on list):

    Exception: Cannot increment reference count on operation GetLocalizedStringOperation, Locale: English (en), Table: TableReference(31972376-72a5-2465-bad4-06c1c682a245 - UI), Entry: TableEntryReference(2060857630720) because it has already been destroyed
    UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject].IncrementReferenceCount () (at ./Library/PackageCache/com.unity.addressables@1.21.19/Runtime/ResourceManager/AsyncOperations/AsyncOperationBase.cs:203)
    UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject].Start (UnityEngine.ResourceManagement.ResourceManager rm, UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle dependency, DelegateList`1[T] updateCallbacks) (at ./Library/PackageCache/com.unity.addressables@1.21.19/Runtime/ResourceManager/AsyncOperations/AsyncOperationBase.cs:528)
    UnityEngine.ResourceManagement.ResourceManager.StartOperation[TObject] (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject] operation, UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle dependency) (at ./Library/PackageCache/com.unity.addressables@1.21.19/Runtime/ResourceManager/ResourceManager.cs:555)
    UnityEngine.Localization.Settings.LocalizedStringDatabase.GetLocalizedStringAsyncInternal (UnityEngine.Localization.Tables.TableReference tableReference, UnityEngine.Localization.Tables.TableEntryReference tableEntryReference, System.Collections.Generic.IList`1[T] arguments, UnityEngine.Localization.Locale locale, UnityEngine.Localization.Settings.FallbackBehavior fallbackBehavior, UnityEngine.Localization.SmartFormat.PersistentVariables.IVariableGroup localVariables, System.Boolean autoRelease) (at ./Library/PackageCache/com.unity.localization@1.4.5/Runtime/Settings/Database/LocalizedStringDatabase.cs:268)
    UnityEngine.Localization.Settings.LocalizedStringDatabase.GetLocalizedStringAsync (UnityEngine.Localization.Tables.TableReference tableReference, UnityEngine.Localization.Tables.TableEntryReference tableEntryReference, System.Collections.Generic.IList`1[T] arguments, UnityEngine.Localization.Locale locale, UnityEngine.Localization.Settings.FallbackBehavior fallbackBehavior, UnityEngine.Localization.SmartFormat.PersistentVariables.IVariableGroup localVariables) (at ./Library/PackageCache/com.unity.localization@1.4.5/Runtime/Settings/Database/LocalizedStringDatabase.cs:258)
    UnityEngine.Localization.LocalizedString.GetLocalizedStringAsync (System.Collections.Generic.IList`1[T] arguments) (at ./Library/PackageCache/com.unity.localization@1.4.5/Runtime/Localized Reference/LocalizedString.cs:311)
    UnityEngine.Localization.LocalizedString.GetLocalizedStringAsync () (at ./Library/PackageCache/com.unity.localization@1.4.5/Runtime/Localized Reference/LocalizedString.cs:263)
    UnityEngine.Localization.PropertyVariants.TrackedObjects.JsonSerializerTrackedObject.ApplyLocale (UnityEngine.Localization.Locale variantLocale, UnityEngine.Localization.Locale defaultLocale) (at ./Library/PackageCache/com.unity.localization@1.4.5/Runtime/Property Variants/Tracked Objects/JsonSerializerTrackedObject.cs:184)
    UnityEngine.Localization.PropertyVariants.GameObjectLocalizer.ApplyLocaleVariant (UnityEngine.Localization.Locale locale, UnityEngine.Localization.Locale fallback) (at ./Library/PackageCache/com.unity.localization@1.4.5/Runtime/Property Variants/GameObjectLocalizer.cs:191)
    UnityEngine.Localization.PropertyVariants.GameObjectLocalizer.ApplyLocaleVariant (UnityEngine.Localization.Locale locale) (at ./Library/PackageCache/com.unity.localization@1.4.5/Runtime/Property Variants/GameObjectLocalizer.cs:165)
    UnityEngine.Localization.PropertyVariants.GameObjectLocalizer.SelectedLocaleChanged (UnityEngine.Localization.Locale locale) (at ./Library/PackageCache/com.unity.localization@1.4.5/Runtime/Property Variants/GameObjectLocalizer.cs:101)
    UnityEngine.Localization.Settings.LocalizationSettings.InvokeSelectedLocaleChanged (UnityEngine.Localization.Locale locale) (at ./Library/PackageCache/com.unity.localization@1.4.5/Runtime/Settings/LocalizationSettings.cs:463)
    UnityEngine.Localization.Settings.LocalizationSettings:set_SelectedLocale(Locale)
    LangButtonIterator:NextLocale() (at Assets/Scripts/Menu/LangButtonIterator.cs:48)
    UnityEngine.EventSystems.EventSystem:Update() (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:530)

    My script attached to the button:
    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using System.Linq;
    5. using UnityEngine;
    6. using UnityEngine.Localization;
    7. using UnityEngine.Localization.Settings;
    8. using UnityEngine.UI;
    9.  
    10. public class LangButtonIterator : MonoBehaviour
    11. {
    12.     private Button button;
    13.     private List<Locale> locales;
    14.     private int localeIndex;
    15.     // Start is called before the first frame update
    16.     void Start()
    17.     {
    18.         button = GetComponent<Button>();
    19.         button.onClick.AddListener(NextLocale);
    20.  
    21.         locales = LocalizationSettings.AvailableLocales.Locales;
    22.         localeIndex = GetLocaleIndex(LocalizationSettings.SelectedLocale.LocaleName);
    23.     }
    24.  
    25.     // Update is called once per frame
    26.     void Update()
    27.     {
    28.      
    29.     }
    30.  
    31.     private int GetLocaleIndex(string localeName)
    32.     {
    33.         for (int i = 0; i < locales.Count; i++)
    34.         {
    35.             if (locales[i].LocaleName == localeName)
    36.             {
    37.                 return i;
    38.             }
    39.         }
    40.         return -1;
    41.     }
    42.  
    43.     private void NextLocale()
    44.     {
    45.         localeIndex++;
    46.         if (localeIndex >= locales.Count)
    47.             localeIndex = 0;
    48.         LocalizationSettings.SelectedLocale = locales[localeIndex];
    49.         Debug.Log($"Changed locale to {locales[localeIndex].LocaleName}");
    50.     }
    51. }
    52.  
    It was able to log stuff out; from the third time I pressed the button, everything worked fine.
    I'm also aware that in the scripting documentation, the following code is included in an IEnumerator function:

    yield return LocalizationSettings.InitializationOperation;

    I tried to do the same, but it seemed that the script execution never moved past this point.
    Thanks for your time :)
     
  4. mrmagic2024

    mrmagic2024

    Joined:
    Jan 6, 2024
    Posts:
    5
    An update - I installed 1.5.0 by downloading the zip file, which I imported manually. And no more error messages! Everything works fine.
     
    karl_jones likes this.