Search Unity

How to fetch the list of changed bundle address?

Discussion in 'Addressables' started by rui_me2zen, Jul 7, 2020.

  1. rui_me2zen

    rui_me2zen

    Joined:
    Jun 29, 2020
    Posts:
    5
    I want to load all changed bundles in loading scene. How do i fetch the list of changed bundle address, then download them?
     
  2. ProtoTerminator

    ProtoTerminator

    Joined:
    Nov 19, 2013
    Posts:
    586
    Is this what you're trying to do?


    Code (CSharp):
    1. Addressables.CheckForCatalogUpdates().Completed += handle =>
    2. {
    3.     Addressables.DownloadDependenciesAsync(new List<object>(handle.Result), Addressables.MergeMode.Union);
    4. };
     
  3. rui_me2zen

    rui_me2zen

    Joined:
    Jun 29, 2020
    Posts:
    5
    But I don't want to load dependencies. I just want to load changed bundles.
    Before Addressables, we can compare the new and old manifests in loading scene, know which bundles have changed, and download the new bundles,then enter main scene
     
  4. ProtoTerminator

    ProtoTerminator

    Joined:
    Nov 19, 2013
    Posts:
    586
    Ah my bad, checked the docs, looks like the handle from
    CheckForCatalogUpdates
    actually contains the catalogs that can be updated. So you would run a
    LoadContentCatalogAsync
    for each catalog id, then
    DownloadDependenciesAsync
    on the keys.

    This should do what you want, then you can await it before entering your main scene.

    Code (CSharp):
    1. async Task UpdateBundles()
    2. {
    3.     // Get catalog keys that can be updated.
    4.     var catalogKeys = await Addressables.CheckForCatalogUpdates().Task;
    5.     if (catalogKeys.Count == 0) return;
    6.  
    7.     // Update catalogs in parallel and wait for them all to complete.
    8.     Task<IResourceLocator>[] catalogTasks = new Task<IResourceLocator>[catalogKeys.Count];
    9.     for (int i = 0; i < catalogKeys.Count; ++i)
    10.     {
    11.         catalogTasks[i] = Addressables.LoadContentCatalogAsync(catalogKeys[i]).Task;
    12.     }
    13.     var locators = await Task.WhenAll(catalogTasks);
    14.  
    15.     // Combine all keys, then download dependencies and wait for them to complete. This will only download bundles we don't already have.
    16.     HashSet<object> keys = new HashSet<object>(locators[0].Keys);
    17.     for (int i = 1; i < locators.Length; ++i)
    18.     {
    19.         keys.UnionWith(locators[i].Keys);
    20.     }
    21.     await Addressables.DownloadDependenciesAsync(new List<object>(keys), Addressables.MergeMode.Union).Task;
    22. }
     
    dirty-rectangle likes this.
  5. rui_me2zen

    rui_me2zen

    Joined:
    Jun 29, 2020
    Posts:
    5
  6. rui_me2zen

    rui_me2zen

    Joined:
    Jun 29, 2020
    Posts:
    5
    @ProtoTerminator I created two catalogs, but they have same locatorId who is AddressablesMainContentCatalog.
    How do i create Multiple catalogs who hava different locatorId?
     
  7. ProtoTerminator

    ProtoTerminator

    Joined:
    Nov 19, 2013
    Posts:
    586
    Hm, I'm not sure about that. @unity_bill give some guidance?