Search Unity

Question Loading String Tables with Addressables

Discussion in 'Localization Tools' started by Sebight, Oct 7, 2022.

  1. Sebight

    Sebight

    Joined:
    Sep 26, 2020
    Posts:
    26
    Hey, I've stumbled upon this docs page (https://docs.unity3d.com/Packages/com.unity.localization@0.11/manual/Addressables.html)

    It looks fine, but doesn't really tell me anything, other than how to create groups and that's it.

    So I create these groups and build the addressables as mentioned in the tutorial and where do I go after? How to actually achieve the possibility that I can change what is actually downloaded at the start of the app?

    Can I edit the downloaded content on the Unity CDN or is it different with localization?

    Thanks! :)
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,279
  3. Sebight

    Sebight

    Joined:
    Sep 26, 2020
    Posts:
    26
    Alright.

    ...and it is later on normally downloaded via
    Code (CSharp):
    1. Addressables.LoadAssetAsync<StringTable>(id);
    correct?

    Or I do not need to do anything with Addressables in custom scripts and it will sort itself? :D
     
    Last edited: Oct 7, 2022
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,279
    Dont do
    Addressables.LoadAssetAsync<StringTable>(id)
    . Use the Localization system to get to the assets, you should not need to load them directly. If you do try that it may work but it will confuse the localization system and likely cause problems (incorrect reference counts in operations).
    If you want a string table either use a LocalizedStringTable or call LocalizationSettings.StringDatabase.GetTableAsync

    Theres some more info here https://docs.unity3d.com/Packages/com.unity.localization@1.3/manual/Scripting.html
     
  5. Sebight

    Sebight

    Joined:
    Sep 26, 2020
    Posts:
    26
    All I need to do really is to load the "remote Addressable localization data", so for that, do I need to call anything to get it updated in the app or is that done automatically?
     
  6. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,279
    If your data is remote and you just want to make sure its pulled from the server then you dont need to do anything different. Follow the standard addressables approach.

    If you are trying to do content updates and want those updates to be applied during the game then you need to make sure that all the localization assets are unloaded or the system wont load the new bundles.

    This thread has more info https://forum.unity.com/threads/cas...addressables-causes-system-exception.1125758/
     
  7. Sebight

    Sebight

    Joined:
    Sep 26, 2020
    Posts:
    26
    All I want is to be able to patch + update translation from server (Unity CDN), so I don't know to which scenario it applies... I guess the first one? :D
     
  8. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,279
    I think its scenario 2 If you want to update translations at a later date. Go with approach 1 and if you have any issues with it using the wrong data then switch to 2.
     
  9. Sebight

    Sebight

    Joined:
    Sep 26, 2020
    Posts:
    26
    Thanks!

    I've dug deeper and implemented part of the code, which seems to work in editor, but not in an actual build...


    Code (CSharp):
    1. private IEnumerator CheckForNewTranslations()
    2.     {
    3.         var initializeOp = Addressables.InitializeAsync();
    4.         yield return initializeOp;
    5.         if (!initializeOp.IsValid())
    6.         {
    7.             Debug.LogError("Failed to initialize Addressables");
    8.         }
    9.        
    10.         var checkForUpdateHandle = Addressables.CheckForCatalogUpdates(false);
    11.         yield return checkForUpdateHandle;
    12.         if (checkForUpdateHandle.Status != UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationStatus.Succeeded)
    13.         {
    14.             Debug.LogError($"CheckForCatalogUpdates failed with status {checkForUpdateHandle.Status}");
    15.             yield break;
    16.         }
    17.        
    18.         var catalogsToUpdate = new List<string>();
    19.         catalogsToUpdate.AddRange(checkForUpdateHandle.Result);
    20.         Addressables.Release(checkForUpdateHandle);
    21.         if (catalogsToUpdate.Count > 0)
    22.         {
    23.             Debug.Log("[Catalog] update available");
    24.             var updateHandle = Addressables.UpdateCatalogs(catalogsToUpdate, false  );
    25.             yield return updateHandle;
    26.             var updateStatus = updateHandle.Status;
    27.             Addressables.Release(updateHandle);
    28.             if (updateStatus != UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationStatus.Succeeded)
    29.             {
    30.                 Debug.LogError($"UpdateCatalogs failed with status {updateHandle.Status}");
    31.                 yield break;
    32.             }
    33.             Debug.Log("[Catalog] updated");
    34.         }
    35.         else
    36.         {
    37.             Debug.LogError("No catalog update available");
    38.         }
    39.  
    40.     }
    When I call this in Start(), it updates to the correct values in Editor (even if I change the local String Tables to something different), but does nothing in Android build. :( I've selected the "Use existing build" option in the Groups window as well.
    upload_2022-10-7_15-17-5.png

    Any idea why this could be happening?
     
  10. Sebight

    Sebight

    Joined:
    Sep 26, 2020
    Posts:
    26
    Actually a little update. It seems to update the string table in editor even if I only call Addressables.InitializeAsync() (and actually none of the code that I provided), but not in the build :/

    Another edit: The editor values semed to be cached locally, which means it does not work at all, not even in editor...
     
    Last edited: Oct 7, 2022
  11. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,279
    It should work in Editor if you are using Use Existing build and you are in Play mode, we dont use Addressables in Edit mode.