Search Unity

Question My Game doesn't get the latest asset bundles when using DownloadDependenciesAsync

Discussion in 'Unity Cloud Content Delivery' started by MaroLFC, Mar 30, 2023.

  1. MaroLFC

    MaroLFC

    Joined:
    Aug 6, 2017
    Posts:
    6
    I'm currently making a test project to test loading assets using addressables and CCD but I'm struggling to get it right

    So I started by making 2 scenes one where it loads everything (_MainScene) and the other is present in the asset bundles to load remotely (AssetsScene) that contains some prefabs and images referencing a few atlases. I have a loader script in the main scene that loads the content here it is

    Code (CSharp):
    1. public class LoadAddressablesWithCCD : MonoBehaviour
    2. {
    3.     //public Image progress;
    4.     public bool clearCacheOnStart = false;
    5.     public TextMeshProUGUI percentageText;
    6.     public TextMeshProUGUI errorText;
    7.     public TextMeshProUGUI sizeText;
    8.     public Slider downloadSlider;
    9.     public Button[] buttons;
    10.     public string[] keys;
    11.     public UnityEvent<float> ProgressEvent;
    12.     public UnityEvent<bool> CompletionEvent;
    13.     private AsyncOperationHandle downloadHandle;
    14.  
    15.     // Use this for initialization
    16.     IEnumerator Start ()
    17.     {
    18.         Application.targetFrameRate = 60;
    19.  
    20.         if (clearCacheOnStart)
    21.         {
    22.             ClearCache();
    23.  
    24.         }
    25.  
    26.  
    27.         AsyncOperationHandle<List<string>> checkHandle = Addressables.CheckForCatalogUpdates();
    28.         Debug.Log(checkHandle.Result);
    29.  
    30.         percentageText.enabled = false;
    31.         errorText.enabled = false;
    32.         sizeText.enabled = false;
    33.         downloadSlider.gameObject.SetActive(false);
    34.  
    35.         /*foreach (var button in buttons)
    36.         {
    37.             button.enabled = false;
    38.  
    39.         }*/
    40.  
    41.         foreach (var key in keys)
    42.         {
    43.             AsyncOperationHandle<long> getDownloadSize = Addressables.GetDownloadSizeAsync(key);
    44.             yield return getDownloadSize;
    45.             if (getDownloadSize.Result > 0)
    46.             {
    47.                 sizeText.enabled = true;
    48.                 sizeText.text = (getDownloadSize.Result/1024) + " kb";
    49.                 ClearCache();
    50.             }
    51.  
    52.         }
    53.        
    54.  
    55.     }
    56.  
    57.  
    58.     public void LoadAdressableBundleByName(string key)
    59.     {
    60.         StartCoroutine(DownloadAdressableBundleByName(key));
    61.     }
    62.  
    63.  
    64.     public static void LoadScene()
    65.     {
    66.         Addressables.LoadSceneAsync("AssetsScene", LoadSceneMode.Additive);
    67.     }
    68.  
    69.     IEnumerator DownloadAdressableBundleByName(string key)
    70.     {
    71.         downloadHandle = Addressables.DownloadDependenciesAsync(key, false);
    72.         //downloadHandle = Addressables.LoadAssetAsync<GameObject>(key);
    73.         float progress = 0;
    74.  
    75.         percentageText.enabled = true;
    76.         downloadSlider.gameObject.SetActive(true);
    77.         while (downloadHandle.Status == AsyncOperationStatus.None)
    78.         {
    79.             float percentageComplete = downloadHandle.GetDownloadStatus().Percent;
    80.             if (percentageComplete > progress * 1.1) // Report at most every 10% or so
    81.             {
    82.                 progress = percentageComplete; // More accurate %
    83.                 ProgressEvent.Invoke(progress);
    84.                 percentageText.enabled = true;
    85.                 percentageText.text = progress*100 +"%";
    86.                 downloadSlider.value = progress;
    87.             }
    88.             yield return null;
    89.         }
    90.  
    91.         CompletionEvent.Invoke(downloadHandle.Status == AsyncOperationStatus.Succeeded);
    92.         Addressables.Release(downloadHandle); //Release the operation handle
    93.         Debug.Log("Loading Done | Key name: " + key);
    94.     }
    95.  
    96.     public void ClearCache()
    97.     {
    98.         foreach (var key in keys)
    99.         {
    100.             Addressables.ClearDependencyCacheAsync(key);
    101.         }
    102.        
    103.         Caching.ClearCache();
    104.     }
    105. }
    The addressable groups are as follows:
    upload_2023-3-31_0-22-42.png

    The groups are set to remote and linked with a bucket i call Android. the problems start here. i started by doing both an android build and addressables asset build to upload to my bucket. The apk loads things successfully from my bucket but when i make any edits and rebuild the asset bundles and upload them to my bucket the build seems to try to load an older asset bundle so it gives an error

    The error:
    upload_2023-3-31_0-29-19.png
    it tries to load the file scenes_scenes_all_eda23223d0735ca61191405d4684fa58.bundle
    The name of the asset it should load in the bucket:
    upload_2023-3-31_0-31-28.png

    I'm not actually a programmer so if there is something I'm doing wrong during loading or through the setup of my addressable and CCD I don't know. any help?
     

    Attached Files:

  2. Julian-Unity3D

    Julian-Unity3D

    Unity Technologies

    Joined:
    Apr 28, 2022
    Posts:
    192
    To fix this, you can try the following steps:
    1. Clear the Addressables cache by calling Addressables.ClearDependencyCacheAsync() for each key you are loading. You can call this method in the ClearCache() method of your LoadAddressablesWithCCD class.

    2. Make sure that you have uploaded the latest version of your asset bundles to your bucket.

    3. Double-check that the key you are passing to DownloadDependenciesAsync() is correct and matches the key of the latest version of your asset bundle in your bucket.

    4. Try rebuilding your asset bundles and uploading them again to your bucket to make sure that the latest version is being used.
    Let me know your results