Search Unity

[Question] About asset unloading

Discussion in 'Localization Tools' started by bcapdevila, Aug 13, 2020.

  1. bcapdevila

    bcapdevila

    Joined:
    Oct 26, 2016
    Posts:
    18
    When it comes to unloading of localization assets, I have found in your documentation and forum answers that the addressable system is responsible for it.

    Could you explain how exactly the localization system does notify the addressable system that all tables of a locale are being unloaded?

    I've been analyzing the source code of your package and it is not easy to find an answer.

    Are there any best practices to follow?

    Thanks!
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,297
    Releasing assets is not fully implemented yet.
    Currently, we only unload when the SelectedLocale is changed which is performed in LocalizedDatabase.OnLocaleChanged
    Code (csharp):
    1.  
    2.         public virtual void OnLocaleChanged(Locale locale)
    3.         {
    4.             foreach (var to in TableOperations.Values)
    5.             {
    6.                 Addressables.Release(to);
    7.             }
    8.  
    9.             m_PreloadOperationHandle = null;
    10.             TableOperations.Clear();
    11.         }
     
  3. bcapdevila

    bcapdevila

    Joined:
    Oct 26, 2016
    Posts:
    18
    Thanks for your reply.

    So as I understand, tables and assets are loaded on demand but just unloaded when switching language.
    Is there a possibility to manually unload tables that we don't need anymore?
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,297
    Yes this should be possible. I have added it to our feature requests
     
  5. KaraArda

    KaraArda

    Joined:
    Jul 11, 2022
    Posts:
    2
    Hi there, is there any behavioral change on how localization package handles asset unloads? We are having a problem with our assets. When the parent gameobject is set to inactive, the assets get unloaded. When the object is set to active again, we see only white boxes in our ui images.

    EDIT: we are using addressables 1.19.19 and localization 1.4.0-exp.1
     
    Last edited: Jul 11, 2022
  6. KaraArda

    KaraArda

    Joined:
    Jul 11, 2022
    Posts:
    2
    We downgraded to localization 1.3.2 and it works now.
     
  7. luistorres_emvenci

    luistorres_emvenci

    Joined:
    Aug 23, 2021
    Posts:
    16
    I've tested forcing the language switch via:
    LocalizationSettings.SelectedLocale = _currentLocale;

    However It does not unload de addressable bundle. Is there something im missing?
    (tested in WebGL)
     
  8. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,297
    How do you know it has not unloaded the bundle? Which bundle is not unloaded?
    For the bundle to be unloaded all references to it must be released. We had some bugs in this area which we fixed in 1.4.2.
     
  9. luistorres_emvenci

    luistorres_emvenci

    Joined:
    Aug 23, 2021
    Posts:
    16
    Thanks for the quick reply!

    I'm currently tracking each request directly on webGL build, below you can see that the first time loading "MainMenu" all Localization bundles are loaded as expected, however the same thing does not happen when reloading "MainMenu".

    (The same happens to other scenes)

    That makes me believe they are getting cached somewhere which should not happen since im using the same configuration in other asset bundles, and those get properly reloaded.
    LocalizationUnload_FirstLoad_MainMenu.PNG LocalizationUnload_SecondLoad_MainMenu.PNG


    Currently using 1.3.2, I'll seek to update if possible.
    ---
    Updating seems to not fix the issue.
    Current versions:
    Unity 2021.3.15f1
    Addressables 1.20.5
    Localization 1.4.2
     
    Last edited: Jan 12, 2023
  10. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,297
  11. luistorres_emvenci

    luistorres_emvenci

    Joined:
    Aug 23, 2021
    Posts:
    16
    Updating seems to not fix the issue.
    Current versions:
    Unity 2021.3.15f1
    Addressables 1.20.5
    Localization 1.4.2

    I've tried using the EventViewer in the past, but I feel like it shows to much information, i'm not really interested on any calls to a already loaded bundle, the main issue is the localization bundles not getting unloaded in the same way as the other bundles. I'll make sure to give it another try tho, and get back with any feedback I get.

    Tell me If there is any other thing I can try, I would be very grateful. This is currently the only and biggest hiccup we are having on the management of our Assets
     
  12. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,297
    The EventViewer should indicate why the bundle is not being released, usually because it still has dependencies.
    You can try loading an empty scene with no localized assets being used and see if the bundles are still loaded. If they are feel free to file a bug report.
     
  13. luistorres_emvenci

    luistorres_emvenci

    Joined:
    Aug 23, 2021
    Posts:
    16
    Update, i've managed to fix it mostly by try and error.
    Below follows the code that fixed it, the only change I added was
    LocalizationSettings.SelectedLocale = null;
    it seems that Localization was not getting properly reloaded since I was changing to the same Locale.

    Thanks for the quick replies ;)

    Code (CSharp):
    1.        
    2. private IEnumerator COR_ForceLocalizationReload()
    3.         {
    4.             LocalizationSettings.SelectedLocaleChanged -= SelectedLocaleChanged;
    5.  
    6.             LocalizationSettings.SelectedLocale = null;
    7.             LocalizationSettings.SelectedLocale = _currentLocale;
    8.  
    9.             var operation = LocalizationSettings.InitializationOperation;
    10.             do
    11.             {
    12.                 if (_currentLocale == null)
    13.                     _currentLocale = LocalizationSettings.SelectedLocaleAsync.Result;
    14.  
    15.                 this.Log("Locale:" + operation.PercentComplete, $"{_currentLocale?.Identifier.CultureInfo.NativeName}");
    16.                 LoadingLocale?.Invoke(operation.PercentComplete, $"{_currentLocale?.Identifier.CultureInfo.NativeName}");
    17.             }
    18.             while (!operation.IsDone);
    19.  
    20.             yield return Tools.Yielders.Get(MIN_LOADTIME);
    21.             LocalizationSettings.SelectedLocaleChanged += SelectedLocaleChanged;
    22.         }
    23.