Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Dynamic content at runtime

Discussion in 'Unity Cloud Content Delivery' started by TS-Trooper, Feb 15, 2024.

  1. TS-Trooper

    TS-Trooper

    Joined:
    Apr 30, 2019
    Posts:
    20
    I am trying to figure out how to set up a project with Addressables and Cloud Content Delivery

    I would like to be able to have different releases in a bucket to swap my content.
    I update the loadpath dynamically, but for some reason it does not load the correct filenames.

    Each bucket has the same files, but different versions. The filenames (and thus paths) are different because of a different GUID at the end.
    I try updating the catalog accordingly, but I it doesn't update the catalog at all: The amount of catalogs to update is 0.

    the code for updating the catalog
    Code (CSharp):
    1.  List<string> catalogsToUpdate = new List<string>();
    2.         AsyncOperationHandle<List<string>> checkForUpdateHandle = Addressables.CheckForCatalogUpdates();
    3.         checkForUpdateHandle.Completed += op =>
    4.         {
    5.             Debug.Log($"CataLogUPdates: {op.Result.Count}");
    6.             catalogsToUpdate.AddRange(op.Result);
    7.         };
    8.         yield return checkForUpdateHandle;
    9.  
    10.         if (catalogsToUpdate.Count > 0)
    11.         {
    12.             Addressables.ClearResourceLocators();
    13.  
    14.             AsyncOperationHandle<List<IResourceLocator>> updateHandle = Addressables.UpdateCatalogs(catalogsToUpdate);
    15.             updateHandle.Completed += op =>
    16.             {
    17.                 for (int i = 0; i < op.Result.Count; i++)
    18.                 {
    19.                     string log = $"LOCATOR {i}:";
    20.  
    21.                     foreach (string s in op.Result[i].Keys)
    22.                     {
    23.                         log += $"\n {s}";
    24.                     }
    25.                     Debug.Log(log);
    26.  
    27.                     Addressables.AddResourceLocator(op.Result[i]);
    28.                 }
    29.             };
    30.             yield return updateHandle;
    31.         }
    32.  
    I manipulate the download string through
    Addressables.ResourceManager.InternalIdTransformFunc = TransformIdFunc

    Code (CSharp):
    1. private string TransformIdFunc(IResourceLocation arg)
    2.     {
    3.         if (arg.ResourceType == typeof(IAssetBundleResource)
    4.             && arg.InternalId.StartsWith("http", System.StringComparison.Ordinal))
    5.         {
    6.             string nw = arg.InternalId;
    7.             bool contains = nw.Contains("EnvironmentTag") || nw.Contains("BucketTag") || nw.Contains("SBadgeTag");
    8.             nw = nw.Replace("EnvironmentTag", envName);
    9.             nw = nw.Replace("BucketTag", bucketid);
    10.             nw = nw.Replace("BadgeTag", badgeName);
    11.             Debug.Log($"{contains} -- transformed the id: " + nw);
    12.             return nw;
    13.         }
    14.  
    15.         return arg.InternalId;
    16.     }
    17.  
    Ultimately I would like to be able to download/use the assets from a specific bucket or (badged) release in the editor or a development build without having to rebuild anything.
     
    Last edited: Feb 15, 2024