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

Disable adding guid to PrimaryKey in Addressables.

Discussion in 'Addressables' started by Syganek, Apr 19, 2021.

  1. Syganek

    Syganek

    Joined:
    Sep 11, 2013
    Posts:
    85
    In Addressables v. 1.16.16 you've started to add a random string of characters (some sort of GUID?) of a
    provideHandle.Location.PrimaryKey
    in an Addressable. For example:

    PrimaryKey of
    defaultcars_assets_all.bundle
    has changed to
    defaultcars_assets_all_f58bf767bd6784e4300e67e929f03798.bundle


    I'm working on a system that allows to load/replace bundles created in one Unity project with bundles from another Unity project. This behaviour breaks the use case that I was using this value for. And additionally, I think it causes the issues I have with dependency errors (because the not replaced addressables are looking for bundles that have been replaced with bundles from the second Unity project) when I'm loading the second project Content Catalogue. Is there a way to disable it?

    I thought that checking the "Unique Bundle IDs" in AddressableAssetSettings will change it but doesn't appear to do anything.

    EDIT:

    I thought that I'll also mention that I do have "Bundle Naming" set to "Filename". The actual name of the bundle file is fine, it's only the PrimaryKey that has the additional characters.
     
    Last edited: Apr 19, 2021
  2. Syganek

    Syganek

    Joined:
    Sep 11, 2013
    Posts:
    85
    Bump? Does anybody have any ideas? I'd really like some input, especially if you're a part of an Addressable team :).
     
  3. apkdev

    apkdev

    Joined:
    Dec 12, 2015
    Posts:
    263
    Not sure if this helps, but the other day I figured out that you can override bundle names by overriding ConstructAssetBundleName in a custom build script:

    Code (CSharp):
    1. using UnityEditor.AddressableAssets.Build.DataBuilders;
    2. using UnityEditor.AddressableAssets.Settings;
    3. using UnityEditor.AddressableAssets.Settings.GroupSchemas;
    4. using UnityEngine;
    5. using UnityEngine.Build.Pipeline;
    6.  
    7. [CreateAssetMenu]
    8. public sealed class BuildScriptRenameBundles : BuildScriptPackedMode
    9. {
    10.     protected override string ConstructAssetBundleName(AddressableAssetGroup assetGroup, BundledAssetGroupSchema schema, BundleDetails info, string assetBundleName)
    11.         => info.Hash.ToString().Substring(0, 8) + ".bundle";
    12. }
    I recommend you look around the BuildScriptPackedMode script, but for your reference here's the default implementation:

    Code (CSharp):
    1. /// <summary>
    2. /// Creates a name for an asset bundle using the provided information.
    3. /// </summary>
    4. /// <param name="assetGroup">The asset group.</param>
    5. /// <param name="schema">The schema of the group.</param>
    6. /// <param name="info">The bundle information.</param>
    7. /// <param name="assetBundleName">The base name of the asset bundle.</param>
    8. /// <returns>Returns the asset bundle name with the provided information.</returns>
    9. protected virtual string ConstructAssetBundleName(AddressableAssetGroup assetGroup, BundledAssetGroupSchema schema, BundleDetails info, string assetBundleName)
    10. {
    11.     string groupName = assetGroup.Name.Replace(" ", "").Replace('\\', '/').Replace("//", "/").ToLower();
    12.     assetBundleName = groupName + "_" + assetBundleName;
    13.     string bundleNameWithHashing = BuildUtility.GetNameWithHashNaming(schema.BundleNaming, info.Hash.ToString(), assetBundleName);
    14.     //For no hash, we need the hash temporarily for content update purposes.  This will be stripped later on.
    15.     if (assetGroup.GetSchema<BundledAssetGroupSchema>()?.BundleNaming ==
    16.         BundledAssetGroupSchema.BundleNamingStyle.NoHash)
    17.     {
    18.         bundleNameWithHashing = bundleNameWithHashing.Replace(".bundle", "_" + info.Hash.ToString() + ".bundle");
    19.     }
    20.  
    21.     return bundleNameWithHashing;
    22. }
    Edit: I just noticed you're asking about just the primary keys - I'm not sure my answer is relevant but you might find what you need in the build script anyway. Reading through the code cleared up a lot of things to me.
     
  4. Syganek

    Syganek

    Joined:
    Sep 11, 2013
    Posts:
    85
    Yeah I think it's only for the names, not PrimaryKeys. I might check this overriding this method anyway.

    For now, I got some workarounds that are working for my use case (at least for now) as I figured that I would need to overwrite a lot of code in the default BuildScript to make it work, and I can't just copy the whole script and create my own version as a lot of the code is invoking internal stuff and I'd basically need to just probably duplicate the whole Addressables Package which is something I don't really want to do.
     
    apkdev likes this.