Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Ungroup assets

Discussion in 'Localization Tools' started by denis_bogdanov, Aug 1, 2022.

  1. denis_bogdanov

    denis_bogdanov

    Joined:
    Apr 20, 2015
    Posts:
    135
    Hello!

    -------------------------------------------------

    I have several projects in one project.
    Each project has its own group with localisation (Look at screenshot "1").
    When the required project is built, the localization group's "IncludeInBuild" property is set to true, when the build is finished it is set to false.
    1.png

    -------------------------------------------------
    The problem.

    Sometimes, I can't exactly track the moment, localization group is ungrouped and returns to default group (Look at screenshot "2"). This seems to happen when unity crashes or when closing unity process via "task manager".
    2.png
    -------------------------------------------------

    Is this normal behaviour or a bug?
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,845
    denis_bogdanov likes this.
  3. denis_bogdanov

    denis_bogdanov

    Joined:
    Apr 20, 2015
    Posts:
    135
    I don't understand how to do

    Please, when you have time could you show me how to change the default group. I have again, two of the groups have ungrouped assets
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,845
    This example shows hot to create a custom resolver.
    in
    GetExpectedGroupName 
    you will need to decide which group the asset should go into.

    Code (csharp):
    1. using System.Collections.Generic;
    2. using UnityEditor;
    3. using UnityEditor.AddressableAssets.Settings;
    4. using UnityEditor.Localization.Addressables;
    5. using UnityEngine;
    6. using UnityEngine.Localization;
    7.  
    8. /// <summary>
    9. /// Places all English assets into a local group and all other languages into a remote group which could be downloaded after the game is released.
    10. /// </summary>
    11. [System.Serializable]
    12. public class GroupResolverExample : GroupResolver
    13. {
    14.     public string localAssetsGroup = "Localization-Local";
    15.     public string remoteAssetsGroup = "Localization-Remote";
    16.  
    17.     [MenuItem("Localization Samples/Create Group Resolver")]
    18.     static void CreateAsset()
    19.     {
    20.         var path = EditorUtility.SaveFilePanelInProject("Create Addressable Rules", "Localization Addressable Group Rules.asset", "asset", "");
    21.         if (string.IsNullOrEmpty(path))
    22.             return;
    23.  
    24.         var instance = ScriptableObject.CreateInstance<AddressableGroupRules>();
    25.         var resolver = new GroupResolverExample();
    26.  
    27.         // Apply our custom group resolver to everything
    28.         instance.LocaleResolver = resolver;
    29.         instance.AssetTablesResolver = resolver;
    30.         instance.AssetResolver = resolver;
    31.         instance.StringTablesResolver = resolver;
    32.  
    33.         // Make this our new AddressableGroupRules
    34.         AssetDatabase.CreateAsset(instance, path);
    35.         AddressableGroupRules.Instance = instance;
    36.     }
    37.  
    38.     public override string GetExpectedGroupName(IList<LocaleIdentifier> locales, Object asset, AddressableAssetSettings aaSettings)
    39.     {
    40.         // Use default behaviour for shared assets
    41.         if (locales == null || locales.Count == 0)
    42.             return base.GetExpectedGroupName(locales, asset, aaSettings);
    43.  
    44.         var locale = locales[0];
    45.         if (locale.Code == "en")
    46.             return localAssetsGroup;
    47.         return remoteAssetsGroup;
    48.     }
    49. }
     
  5. denis_bogdanov

    denis_bogdanov

    Joined:
    Apr 20, 2015
    Posts:
    135
    Hello again

    I'm sorry, but I can't get it to work :(
    --------------------------

    I will describe the problem in more detail and I have attached a video in the archive.

    1)I have three tables Sudoku, Blocks and Word Search.
    2)I have created three addressable groups called "Sudoku", "Blocks" and "Word Search" for each of them.
    3)In these groups, I put string assets:

    Group Sudoku->.
    Sudoku_en_EN
    Sudoku_fr_FR
    Sudoku_it_IT.
    ....

    Group Blocks->
    Blocks_en_EN
    Blocks_fr_FR
    Blocks_it_IT
    ....

    .....

    3) Sometimes string assets return to default groups of "Localization-String-Tables-English (en)" "Localization-String-Tables-French (fr)"...

    4) I have to put them back.

    5) When I make a build for example a sudoku group I set the "includeinbuild" property to "true".

    6) I create a rule, but there you can only create a common group for all string assets.

    What I expected:

    I create a rule for Sudoku Assets and set a common group named Sudoku
    I create a rule for Blocks assets and set the common group to be named Blocks
    ...

    But the rule applies to all the assets, in the video I show this point.

    Please help me what am I doing wrong and can this be implemented?
     

    Attached Files:

  6. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,845
    Try this

    Code (csharp):
    1. public class CustomResolver : GroupResolver
    2. {
    3.     public override string GetExpectedGroupName(IList<LocaleIdentifier> locales, Object asset, AddressableAssetSettings aaSettings)
    4.     {
    5.         if (asset.name.Contains("Sudoku"))
    6.             return "Sudoku";
    7.         if (asset.name.Contains("BlockPuzzles"))
    8.             return "BlockPuzzles";
    9.         if (asset.name.Contains("Cards"))
    10.             return "Cards";
    11.         if (asset.name.Contains("WordSearch"))
    12.             return "WordSearch";
    13.         return base.GetExpectedGroupName(locales, asset, aaSettings);
    14.     }
    15.  
    16.     [MenuItem("Localization/Create Rules")]
    17.     static void CreateRulesAsset()
    18.     {
    19.         var path = EditorUtility.SaveFilePanelInProject("Create Addressable Rules", "Localization Addressable Group Rules.asset", "asset", "");
    20.         if (string.IsNullOrEmpty(path))
    21.             return;
    22.  
    23.         var instance = ScriptableObject.CreateInstance<AddressableGroupRules>();
    24.         var resolver = new GroupResolverExample();
    25.  
    26.         // Apply our custom group resolver to everything
    27.         instance.LocaleResolver = new GroupResolverExample(); // default
    28.         instance.AssetTablesResolver = new CustomResolver();
    29.         instance.AssetResolver = new CustomResolver();
    30.         instance.StringTablesResolver = new CustomResolver();
    31.  
    32.         // Make this our new AddressableGroupRules
    33.         AssetDatabase.CreateAsset(instance, path);
    34.         AddressableGroupRules.Instance = instance;
    35.     }
    36. }
    Run the menu command Localization/Create Rules and Save the project. It should now support different groups based on the asset name. Make sure to commit the ProjectSettings/EditorBuildSettings.asset file.
     
    denis_bogdanov likes this.
  7. denis_bogdanov

    denis_bogdanov

    Joined:
    Apr 20, 2015
    Posts:
    135


    It's working! I figured out how to do it!

    Thank you very much! Karl Jones is the best of the best :)
     
    karl_jones likes this.
  8. denis_bogdanov

    denis_bogdanov

    Joined:
    Apr 20, 2015
    Posts:
    135


    I have one more question)

    Under "Unfixeble Rules" there are warnings. How do I know what it is and fix it or can I ignore it?
    Screenshot_2.png
     
  9. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,845
    That means you have references to the locales through a script in a scene.
    https://docs.unity3d.com/Packages/c...AddressableAssetsAnalyze.html#unfixable-rules

    You should not reference the locales in a script like this:

    Code (csharp):
    1. public Locale myLocale
    If you do this then Unity will create 2 versions of the Locale, 1 that is referenced and built into the game and another that is packed into the Asset Bundles and used by the localization system.
    Do not reference any Localization assets through scripts or this will happen.

    Instead, fetch them from the system at runtime. You can also use LocaleIdentifier if you need a way to set a locale in a script variable.

    E.G

    Code (csharp):
    1. public LocaleIdentifier myLocaleId;
    2. Locale myLocale;
    3.  
    4. IEnumerator Start()
    5. {
    6.     yield return LocalizationSettings.InitializationOperation;
    7.     myLocale = LocalizationSettings.AvailableLocales.GetLocale(myLocaleId);
    8. }
     
    Last edited: Aug 10, 2022
    denis_bogdanov likes this.
  10. denis_bogdanov

    denis_bogdanov

    Joined:
    Apr 20, 2015
    Posts:
    135
    Fixed! I have replaced Locale -> LocaleIdentifier. Thank you very much!

    I didn't find it in the documentation, is "Bundle Layout Preview" a problem or just information?

    Screenshot_2.png
     
    karl_jones likes this.
  11. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,845
    That's just Information to show you the contents of each asset bundle that will be generated.
     
    denis_bogdanov likes this.
  12. denis_bogdanov

    denis_bogdanov

    Joined:
    Apr 20, 2015
    Posts:
    135
    Thank you for your time and help!
     
    karl_jones likes this.