Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Bug - Addressables with same names are not validated and breaks the build

Discussion in 'Addressables' started by rastlin, Nov 24, 2019.

  1. rastlin

    rastlin

    Joined:
    Jun 5, 2017
    Posts:
    127
    So I had two assets with the same name in one group, not idea how this happened - I assume due to some upgrade issues.

    When I tried to build the assets I got this:
    After some digging it turned out it was due to those duplicated names. This should be validated somehow before the build to give some more meaningful error.

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

    Another issues is, after recent upgrades (I'm @1.4), the changes to load path for Asset Bundle Schema are not persisted in schema file. I need to change this directly in the file for it to persist.
     
    RobbyZ likes this.
  2. duartedd

    duartedd

    Joined:
    Aug 1, 2017
    Posts:
    91
    I have this same error - i am trying to locate what that key belongs to - would be nice to have the name associated to that key - gonna dig through some files
     
    RobbyZ likes this.
  3. unity_bill

    unity_bill

    Unity Technologies

    Joined:
    Apr 11, 2017
    Posts:
    1,023
    Thanks for letting us know. we intentionally support giving different assets the same address. The general use case is you might give two assets the address "tank_texture" but then give them different labels ("hd", "sd"). Which can ease loading.

    So, why did your example blow up? Turns out it has to do with choosing "pack separately" on the group. If you do pack together, your build will work. With the separate option, we try to name the bundle after the asset's address. I'm putting a ticket in our backlog to fix this by detecting the issue and changing the bundle name.

    Note that our "fix" will not detect or disallow duplicate names.
     
    Ben-BearFish and RobbyZ like this.
  4. rastlin

    rastlin

    Joined:
    Jun 5, 2017
    Posts:
    127
    Thanks Bill for explanation. Nice to hear this specific use case will be handled.
     
  5. RobbyZ

    RobbyZ

    Joined:
    Apr 17, 2015
    Posts:
    33
    Thank you for the info. Unfortunately, the pack together option (as I understand it) would bunch all the assets into one file. This defeats one of the key use cases for addressables (separating asset files out so they can be easier patched by the underlying distribution platforms).
     
  6. senfield

    senfield

    Joined:
    Apr 1, 2019
    Posts:
    31
    This bug is still present in Addressables version 1.6.0
     
  7. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    @unity_bill Can you make sure to put that part in? Knowing the offending key location/asset is critical for us with massive projects. Otherwise, it's a crapshoot to guess what asset it is.
     
  8. ThomasBowker

    ThomasBowker

    Joined:
    Jul 6, 2013
    Posts:
    3
    Here's a very simple analyze rule that will show you any duplicate addressable names in your groups.
    Put it in an editor folder, open the Addressables Analyze window and select Unfixable Rules -> Check Duplicate Addressable Names.

    Edit: put in the string fix from AutumnYard below.

    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEditor.AddressableAssets.Settings;
    3. namespace UnityEditor.AddressableAssets.Build.AnalyzeRules
    4. {
    5.     [InitializeOnLoad]
    6.     class RegisterAnalyzeDuplicateAddressableNames
    7.     {
    8.         static RegisterAnalyzeDuplicateAddressableNames()
    9.         {
    10.             AnalyzeSystem.RegisterNewRule<AnalyzeDuplicateAddressableNames>();
    11.         }
    12.     }
    13.  
    14.     class AnalyzeDuplicateAddressableNames : AnalyzeRule
    15.     {
    16.    
    17.    
    18.         //--------------------------------
    19.    
    20.         public override bool CanFix
    21.         {
    22.             get { return false;}
    23.         }
    24.         public override string ruleName
    25.         {
    26.             get { return "Check Duplicate Addressable Names"; }
    27.         }
    28.    
    29.         //--------------------------------
    30.    
    31.         public override List<AnalyzeResult> RefreshAnalysis(AddressableAssetSettings settings)
    32.         {
    33.             List<AnalyzeResult> results = new List<AnalyzeResult>();
    34.             HashSet<string> addressable_names = new HashSet<string>();
    35.        
    36.             for (int i = 0; i < settings.groups.Count; ++i)
    37.             {
    38.                 AddressableAssetGroup group = settings.groups[i];
    39.                 foreach (AddressableAssetEntry entry in group.entries)
    40.                 {
    41.                     // ToLower fix from AutumnYard
    42.                     string entry_add = entry.address.ToLower();
    43.                     if (addressable_names.Contains(entry_add))
    44.                     {
    45.                         AnalyzeResult r = new AnalyzeResult();
    46.                         r.resultName = $"{group.name}:{entry_add}";
    47.                         r.severity = MessageType.Warning;
    48.                         results.Add(r);
    49.                     }
    50.                     else
    51.                     {
    52.                         addressable_names.Add(entry_add);
    53.                     }
    54.                
    55.                 }
    56.             }
    57.             return results;
    58.         }
    59.         public override void FixIssues(AddressableAssetSettings settings)
    60.         {
    61.             base.FixIssues(settings);
    62.         }
    63.         public override void ClearAnalysis()
    64.         {
    65.             base.ClearAnalysis();
    66.         }
    67.    
    68.         //--------------------------------
    69.     }
    70. }
     
    Last edited: Feb 22, 2020
  9. AutumnYard

    AutumnYard

    Joined:
    Feb 20, 2014
    Posts:
    13
    It would really really really help us if we could pick for the "Simplify Addressable Names" to ignore the extension. Most of our duplicates came from our naming conventions of materials, textures, fbx and other stuff often sharing the same name.

    Could that be possible?
     
  10. AutumnYard

    AutumnYard

    Joined:
    Feb 20, 2014
    Posts:
    13
    By the way, I just noticed why, even after making sure there were no duplicates in the Addressable Names list, there was still the error. Bundle name generation is all lowercase.
    I found out printing the variable assetBundleName in the file "Library\PackageCache\com.unity.addressables@1.6.2\Editor\Build\DataBuilders\BuildScriptPackedMode.cs", when the Add method throws an exception.

    The bundle naming generation is all in lowercase, so ThomasBowker code should be all in lowercase to add false negatives to the checking:

     
    andreiagmu and ThomasBowker like this.
  11. AutumnYard

    AutumnYard

    Joined:
    Feb 20, 2014
    Posts:
    13
    Okay so I made a Fix for this analyze rule that adds the extension to the duplicated addresses.

    It's not perfect, but it has helped me greatly. Gonna bump this thread just in case somebody else finds this to be helpful.

    Code (CSharp):
    1.  
    2.     public override void FixIssues( AddressableAssetSettings settings )
    3.     {
    4.       HashSet<string> addressable_names = new HashSet<string>();
    5.  
    6.       for( int i = 0; i < settings.groups.Count; ++i )
    7.       {
    8.         AddressableAssetGroup group = settings.groups[i];
    9.         foreach( AddressableAssetEntry entry in group.entries )
    10.         {
    11.           if( addressable_names.Contains( entry.address.ToLower() ) )
    12.           {
    13.             // For each duplicated entry, add the extension to the address
    14.             string ext = System.IO.Path.GetExtension( entry.AssetPath );
    15.             UnityEngine.Debug.Log( $"Found duplicate: {entry.AssetPath} of extension {ext}. Fixing." );
    16.             entry.address += ext;
    17.           }
    18.           else
    19.           {
    20.             addressable_names.Add( entry.address.ToLower() );
    21.           }
    22.         }
    23.       }
    24.     }
     
    andreiagmu likes this.
unityunity