Search Unity

[bug/feature] allow assets in groups belonging other groups referencing this asset via folders

Discussion in 'Addressables' started by nik_d, Jun 12, 2019.

  1. nik_d

    nik_d

    Joined:
    Apr 27, 2018
    Posts:
    66
    workaround:
    in AddressableAssetsBuildContext.cs:
    Code (CSharp):
    1.         public HashSet<string> uniqueGuids = new HashSet<string>(); //**addressables: bugfix for groups including sub-folder or asset of the folder in other group
    in BuildScriptFastMode.cs ProcessGroup(...):
    Code (CSharp):
    1.             foreach (var a in allEntries) {
    2.                 //**addressables: bugfix for groups including sub-folder or asset of the folder in other group
    3.                 if (aaContext.uniqueGuids.Contains(a.guid)) continue;
    4.                 aaContext.uniqueGuids.Add(a.guid);
    5.                
    6.                 aaContext.locations.Add(new ContentCatalogDataEntry(a.GetAssetLoadPath(true), typeof(AssetDatabaseProvider).FullName, a.CreateKeyList()));
    7.             }
    in BuildContent.cs BundleBuildContent(...)
    Code (CSharp):
    1.                     //**addressables: bugfix for groups including sub-folder or asset of the folder in other group
    2.                     //TODO: move to ProcessGroup just like FastMode do
    3.                     if (Addresses.ContainsKey(asset)) {
    4.                         continue;
    5.                     }
    in AddressableAssetSettings.cs CreateSubEntryIfUnique(...):
    Code (CSharp):
    1.             //**addressables: bugfix for groups including sub-folder or asset of the folder in other group
    2.             /***
    3.             //if the sub-entry already exists update it's info.  This mainly covers the case of dragging folders around.
    4.             if (entry.IsSubAsset)
    5.             {
    6.                 entry.parentGroup = parentEntry.parentGroup;
    7.                 entry.IsInResources = parentEntry.IsInResources;
    8.                 entry.address = address;
    9.                 entry.ReadOnly = true;
    10.                 return entry;
    11.             }
    12.             ***/
     
  2. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    Please explain the situation, and what outcome you are trying to achieve. It sounds like you have a folder "x" with "prefabA" in it (and other stuff). You want to mark "x" addressable in one group, and mark "prefabA" as addressable in another. Is that right? Then what do you want to happen?
     
  3. nik_d

    nik_d

    Joined:
    Apr 27, 2018
    Posts:
    66
    Use case 1:
    (put assets to differently loaded bundles by addressables configuration):
    Addressables Groups:
    Code (CSharp):
    1.  
    2.     * Embedded bundles
    3.         - bg/LoadingScreen => Assets/FullscreenBg/LoadingScreen.png
    4.         - arena/Forest => Assets/Prefabs/Arenas/Forest.prefab
    5.         - char/Roland => Assets/Prefabs/Characters/Roland/
    6.         - char/Kobold => Assets/Prefabs/Characters/Kobold/
    7.         ...
    8.     * Downloadable bundles
    9.         - bg => Assets/FullscreenBg/
    10.         - arena => Assets/Prefabs/Arenas/
    11.         - char => Assets/Prefabs/Characters/
    12.         ...
    13.  
    So "bg/LoadingScreen" texture, "arena/Forest" prefab and "char/Roland/***" assets are available asap for the first mission/tutorial (during which "Downloadable" are pre-downloading).
    Without addressables changes I would be forced to change project structure: f.e. to move all "embedded" assets out of their logic folders (to something like ArenasStartup / CharactersStartup folders) - light pain.

    Use case 2:
    (allow to auto-share assets within referenced folders)
    Code (CSharp):
    1.  
    2.     * Embedded bundles
    3.         - char/Roland => Assets/Prefabs/Characters/Roland/
    4.         - char/Kobold => Assets/Prefabs/Characters/Kobold/
    5.     * Downloadable bundles
    6.         - char => Assets/Prefabs/Characters/
    7.  
    => auto-processing ala "Addressables/Analyze/Check Duplicate Bundle Dependencies"
    Code (CSharp):
    1.  
    2.     * Shared embedded bundles
    3.         - Assets/Prefabs/Characters/Roland/textures/Common_with_Kobold.png
    4.     * Embedded bundles
    5.         - char/Roland => Assets/Prefabs/Characters/Roland/
    6.         - char/Kobold => Assets/Prefabs/Characters/Kobold/
    7.     * Shared downloadable bundles
    8.         - Assets/Prefabs/Characters/Common/xxx.asset
    9.         ...
    10.     * Downloadable bundles
    11.         - char => Assets/Prefabs/Characters/
    12.  
    Without the fix I would be forced to significantly change project structure (>20k assets) and refuse to auto-build "shared" groups - pain =)
     
  4. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    For use case one, it sounds like all you are after is a naming change. Meaning if you mark folder "x" as addressable, and give it a address "coolStuff", you want "x/prefabA" to be loadable as "coolStuff/prefabA". That feels achievable via a better default naming. If prefabA is not addressable (which makes it loadable under it's parent folder name "coolStuff/prefabA"), then becomes addressable, we should ensure it becomes so with the same name it had before.

    For usecase two, this is specifically for running the CheckDuplicateDependencies analyze rule? To pull out duplicated assets into their own bundles? Naming of assets won't have anything to do with this. It sounds like what you actually want here is for the analyze rule to be capable of running against specific subsets of groups.
     
  5. nik_d

    nik_d

    Joined:
    Apr 27, 2018
    Posts:
    66
    It's not about assets naming, but in assets belonging to groups/bundles.
    I just checked the problem again and have found it lies not with separate assets but with separate subfolders.

    Let assume (addressable 0.8.6 without fix):
    GroupA: skills/Roland => Assets/Textures/Skills/Roland/ and GroupB: skills => Asset/Textures/Skills/
    Then
    Addressables.LoadAssetAsync<Texture>("skills/Roland/Attack_Roland_01.png")
    works correctly in "Fast Mode".

    But "Build->Build Player Content" for "Packed Mode" fails with error: "ArgumentException: An item with the same key has already been added. Key: <guid>"

    Sample project attached.
     

    Attached Files:

  6. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    Oh, you are marking a folder as addressable in one group, then a sub folder as addressable in another. I guess we never checked that case. Bug filed. thanks.