Search Unity

Resolved Have the localization table into an AssetBundle

Discussion in 'Localization Tools' started by JulianMC, May 6, 2021.

  1. JulianMC

    JulianMC

    Joined:
    Dec 30, 2019
    Posts:
    26
    Hi, I'm not sure if you can respond to my question but I'll try just in case you can help me.

    Where I'm doing my internship, they have a plugin they made than turns a prefab with all the gameobjects (3D objects with textures, objects with TMP components, etc) in the scene into an assetBundle.

    When the assetBundle is build, the materials components that reference images for the textures (albedo and normal map) goes with bundle as well as the scripts that reference audio clips.

    My question is: is there a way to make the localization table collection to go with it?
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,291
    This is already what's happening.
    We place tables and assets into various addressable groups which are then built into asset bundles.
    https://docs.unity3d.com/Packages/com.unity.localization@0.11/manual/Addressables.html

    You can move the tables into different groups so if you wanted them into the same asset bundle you would put them Into the same group.
     
  3. JulianMC

    JulianMC

    Joined:
    Dec 30, 2019
    Posts:
    26
    I have this script

    Code (CSharp):
    1. public static InitializeLocalizationTable instance;
    2.  
    3.         public LocalizedStringTable localizedStringTable; // The localization table used for the scene
    4.  
    5.         void Awake()
    6.         {
    7.             if (instance == null)
    8.             {
    9.                 instance = this;
    10.             }    
    11.         }
    12.  
    13.         void Start()
    14.         {
    15.             Addressables.LoadAssetAsync<LocalizedStringTable>("LocalizationTestTable").Completed += OnLoadDone;
    16.         }
    17.  
    18.         private void OnLoadDone(UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle<LocalizedStringTable> obj)
    19.         {
    20.             // In a production environment, you should add exception handling to catch scenarios such as a null result.
    21.             localizedStringTable = obj.Result;
    22.  
    23.         }

    But I always get this error

    Exception encountered in operation CompletedOperation, status=Failed, result= : Exception of type 'UnityEngine.AddressableAssets.InvalidKeyException' was thrown., Key=default, Type=UnityEngine.Localization.LocalizedStringTable
    UnityEngine.AddressableAssets.Addressables:LoadAssetAsync<UnityEngine.Localization.LocalizedStringTable> (object)
    ARVisionGames.Localization.InitializeLocalizationTable:Start () (at Assets/com.arvisiongames.ariddle-unityframework/Runtime/Localization/Scripts/InitializeLocalizationTable.cs:27)


    What am I doing wrong? with all the others string tables and locals I can get them but not with this.


    line 27 is 15 in the code I send
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,291
    Did you build the addressables?
    Is this in the player or editor?
     
  5. JulianMC

    JulianMC

    Joined:
    Dec 30, 2019
    Posts:
    26
    I didn't build them

    I just have them here, in the script I can get the locales using their labels (Locale) or the string tables (Locale-fr) but I can't get the localized string table (LocalizationTestTable)
    upload_2021-5-7_16-22-12.png

    I have a game object with the script I send you in my scene
    upload_2021-5-7_16-28-27.png
     
  6. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,291
  7. JulianMC

    JulianMC

    Joined:
    Dec 30, 2019
    Posts:
    26
    I didn't I just changed them into the default group
    There is nothing here about the table collection

    upload_2021-5-10_8-46-41.png
     
  8. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,291
    Could you share the project? I suspect there may be an issue with using the Default Group.
     
  9. JulianMC

    JulianMC

    Joined:
    Dec 30, 2019
    Posts:
    26
    I can't, I'm sorry...

    But am I doing things right? Is this the way to access them once they are in an asset bundle or this is not the way to do it?

    Is there a way to access the collection using the shared data string table?

    [EDIT]
    The collection table can't be marked as, is that the reason why I can't access it?
    upload_2021-5-10_9-7-46.png
     
    Last edited: May 10, 2021
  10. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,291
    It should not matter where they are stored, asset bundle or not. The addressables system handles all of that.
    A collection is an Editor only asset so wont be part of an asset bundle or accessible in the player.

    If you move the assets back into their original groups does it work?
     
  11. JulianMC

    JulianMC

    Joined:
    Dec 30, 2019
    Posts:
    26
    I moved them back, but the collection I was the one who added it to the default group.

    After moving them back to their groups they all work, but I still don't know how to get the collection.

    I have this script where I want to set the collection that will by used for the scene.
    upload_2021-5-10_10-7-38.png

    This other script I made will get the collection table selected from the InitializeLocalizationTable dynamically so everything will be done via script.
    upload_2021-5-10_10-9-50.png

    But when the asset bundle is created the InitializeLocalizationTable script (first picture), can't find the table so the other script doens't know which table collection to use for the text.
     

    Attached Files:

  12. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,291
    Im not sure I understand.

    I just noticed this from your earlier post

    Code (csharp):
    1. Addressables.LoadAssetAsync<LocalizedStringTable>("LocalizationTestTable").Completed += OnLoadDone;
    This is incorrect.
    Take a look at https://docs.unity3d.com/Packages/c...Engine.Localization.LocalizedStringTable.html

    You want to use either the TableChanged event or GetTable()

    E.G

    Code (csharp):
    1. localizedStringTable.GetTable();
    We also have several samples under LoadingStrings (accessible in the package manager window) that are a good resource to get started.
     
  13. JulianMC

    JulianMC

    Joined:
    Dec 30, 2019
    Posts:
    26
    No, this is not what I want.

    Once I build the asset bundle, if I instantiate it in another project (example a cube with some materials and textures) the cube will apear with all his materials and textures, but not with the string tables and collections, the script I made " InitializeLocalizationTable " can't find the collection because he's looking in the assets folder (where there are no tables) for the table but not in the AssetBundle.
     
  14. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,291
    Im not clear what you are doing. You want to build an asset bundle to use in a different project?
    Providing you build the addressables and include the addressable catalog then it should work. Can you make a simple project to show what you are trying to do, it may be easier for me to understand?
     
  15. JulianMC

    JulianMC

    Joined:
    Dec 30, 2019
    Posts:
    26
    I wanna try another approach, I understand now that the collection is an Editor Asset only, so I can't have into an asset Bundle. But the string tables yes.

    If I have the string tables, can I create a collection VIA script and then add the tables to the collection VIA script too?

    Do something like this, like clicking in add but via script
    upload_2021-5-10_15-41-36.png

    So It turns into this
    upload_2021-5-10_15-42-10.png



    [EDIT]
    I'm sorry for all the questions and the issues
     
    Last edited: May 10, 2021
  16. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,291
  17. JulianMC

    JulianMC

    Joined:
    Dec 30, 2019
    Posts:
    26
    Ok, but if I understand correctly, if I build an asset bundle it wont build because this code is on UnityEditor?
     
  18. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,291
    The tables and shared table data are not editor only. Just the collection. The collection is there purely for editor purposes, but the changes you make through it will be reflected in the player builds.

    How are you building your asset bundles?
    Are you doing it through addressables?
     
  19. JulianMC

    JulianMC

    Joined:
    Dec 30, 2019
    Posts:
    26
    I'm using the Asset Bundle Browser package.

    Is there a way to do this :
    localizedString.RefreshString();

    Without using localizedString?
     
  20. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,291
    Ok I see. So the Asset Bundle Browser will build asset bundles but it will not support Addressables.
    Addressable assets are more than asset bundles. Whilst the data may come from an asset bundle it can also come from many other sources and so requires the Addressables config information to be built as well.
    You should not build the Addressables through the Asset Bundle Browser, it will not build all the required files. You should build them through the Addressables system
    https://docs.unity3d.com/Packages/c...tGuide.html#9-build-preview-and-configuration

    I would not recommend using Asset Bundles(via the Asset Bundle Browser) and Addressables together as its likely to cause confusion. Addressables is designed to simplify the whole thing so that you don't need to worry about managing the asset bundles or using the low level API. You just ask for an asset with a certain address and the system will find it and load it.
    Open the Addressables window and you will see that you have similar functionality to the Asset Bundles Builder.

    upload_2021-5-11_14-31-40.png
     
  21. JulianMC

    JulianMC

    Joined:
    Dec 30, 2019
    Posts:
    26
    you are talking about this here? Do I have to build this? If yes, after building it how can I get the collection table?
    upload_2021-5-11_9-54-36.png
     
  22. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,291
    Yes thats it.
    Once built then to get a collection you can either use a LocalizedStringTable:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.Localization;
    4. using UnityEngine.Localization.Metadata;
    5. using UnityEngine.Localization.Settings;
    6. using UnityEngine.Localization.Tables;
    7.  
    8. public class LocalizedStringTableExample : MonoBehaviour
    9. {
    10. public LocalizedStringTable m_StringTable = new LocalizedStringTable { TableReference = "My Strings" };
    11.  
    12. string m_TranslatedStringHello;
    13. string m_TranslatedStringGoodbye;
    14. string m_TranslatedStringThisIsATest;
    15.  
    16. void OnEnable()
    17. {
    18.    m_StringTable.TableChanged += LoadStrings;
    19. }
    20.  
    21. void OnDisable()
    22. {
    23.    m_StringTable.TableChanged -= LoadStrings;
    24. }
    25.  
    26. void LoadStrings(StringTable stringTable)
    27. {
    28.    m_TranslatedStringHello = GetLocalizedString(stringTable, "Hello");
    29.    m_TranslatedStringGoodbye = GetLocalizedString(stringTable, "Goodbye");
    30.    m_TranslatedStringThisIsATest = GetLocalizedString(stringTable, "This is a test");
    31. }
    32.  
    33. static string GetLocalizedString(StringTable table, string entryName)
    34. {
    35.    var entry = table.GetEntry(entryName);
    36.  
    37.    // We can also extract Metadata here
    38.    var comment = entry.GetMetadata<Comment>();
    39.    if (comment != null)
    40.    {
    41.        Debug.Log($"Found metadata comment for {entryName} - {comment.CommentText}");
    42.    }
    43.  
    44.    return entry.GetLocalizedString(); // We can pass in optional arguments for Smart Format or String.Format here.
    45. }
    46.  
    47. void OnGUI()
    48. {
    49.    if (!LocalizationSettings.InitializationOperation.IsDone)
    50.    {
    51.        GUILayout.Label("Initializing Localization");
    52.        return;
    53.    }
    54.  
    55.    GUILayout.Label(m_TranslatedStringThisIsATest);
    56.    GUILayout.Label(m_TranslatedStringHello);
    57.    GUILayout.Label(m_TranslatedStringGoodbye);
    58. }
    59. }
    You can also just call GetTableAsync, its essentially what a LocalizedStringTable does.
    These will give you the StringTable for the SelectedLocale .
    If you want a table for a different Locale you can also pass in the locale into GetTableAsync.

    E.G

    Code (csharp):
    1. var locale = LocalizationSettings.AvailableLocales.GetLocale("fr");
    2. var tableOperation = LocalizationSettings.StringDatabase.GetTableAsync("My Strings", locale);
    3. yield return tableOperation;
     
  23. JulianMC

    JulianMC

    Joined:
    Dec 30, 2019
    Posts:
    26
    Hi, I just got time to build the addressables.
    This is what he build right? How do I use them?
    upload_2021-5-12_9-28-17.png
     
  24. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,291
    Yeah thats correct.
    They will be automatically bundled with the build so you dont need to do anything.
    You use them like I showed above by calling the various localization methods we will call into Addressables which will load them .
    If you want to do something more advanced you can read the Addressables docs here https://docs.unity3d.com/Packages/com.unity.addressables@1.18/manual/index.html
     
  25. JulianMC

    JulianMC

    Joined:
    Dec 30, 2019
    Posts:
    26
    Ok, I understand, but now I come across another question.

    The project I'm working on is for a company (I'm doing an internship) that builds asset bundles and then upload them to playfab. They don't use Asset Bundle Browser (I was just using this for tests purposes), they use another one that I believe they made.

    When this asset bundle of THE ROOM is build , the addressables bundles (Last picture I send) will be bundled into THE ROOM asset bundle to?
     
    Last edited: May 12, 2021
  26. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,291
    I cant say for sure but I suspect it wont work if you are just uploading asset bundles. The system would need to support Addressables. This is going out of my area of expertise now, you may have more luck posting in the Addressables forum where the team who owns Addressables and Asset bundles can be found. https://forum.unity.com/forums/addressables.156/

    Localization just uses Addressables, we dont do anything custom so if you can get Addressables to work then Localization should also work.
     
  27. JulianMC

    JulianMC

    Joined:
    Dec 30, 2019
    Posts:
    26
    Ok, I get it, I'll ask them, thank you very much for your help

    One quick last question, when you say this you mean going to the build settings and build, right?
     
  28. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,291
    Yes but this is for a player build not asset bundle.