Addressables don't load remote catalog twice

I’m trying to download assets from my AWS S3 bucket. So I’m using this script:

using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.AddressableAssets.ResourceLocators;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.ResourceManagement.ResourceLocations;

public class AssetLoader : MonoBehaviour
{
    public string catalogPath;
    public string myLabel;
    public List<IResourceLocation> locations;       

    public void initAddressables()
    {
        uiManager.loading.SetActive(true);
        AsyncOperationHandle<IResourceLocator> handle = Addressables.InitializeAsync();
        handle.Completed += initDone;
    }

  
    private void initDone(AsyncOperationHandle<IResourceLocator> obj)
    {
        if (obj.Status == AsyncOperationStatus.Succeeded)
        {
            LoadCatalog();
        }
    }
 

    void LoadCatalog()
    {
        AsyncOperationHandle<IResourceLocator> handle;
      
        handle = new AsyncOperationHandle<IResourceLocator>();      
        handle = Addressables.LoadContentCatalogAsync(catalogPath);      
        handle.Completed += LoadCatalogsCompleted;     
      
    }
    void LoadCatalogsCompleted(AsyncOperationHandle<IResourceLocator> obj)
    {
        if (obj.Status == AsyncOperationStatus.Succeeded)
        {
            LoadResourceLocation();
        }
        else
        {
            Debug.LogError("LoadCatalogsCompleted is failed");
        }
    }

    void LoadResourceLocation()
    {
        AsyncOperationHandle<IList<IResourceLocation>> handle = Addressables.LoadResourceLocationsAsync(myLabel);
        handle.Completed += LocationsLoaded;
    }
    void LocationsLoaded(AsyncOperationHandle<IList<IResourceLocation>> obj)
    {
        if (obj.Status == AsyncOperationStatus.Succeeded)
        {
            locations = new List<IResourceLocation>(obj.Result);
            LoadDependency();
        }
        else
        {
            Debug.LogError("locationsLoaded is failed");
        }
    }

    void LoadDependency()
    {
        AsyncOperationHandle handle = Addressables.DownloadDependenciesAsync(myLabel);
        handle.Completed += DependencyLoaded;
    }
    void DependencyLoaded(AsyncOperationHandle obj)
    {
        if (obj.Status == AsyncOperationStatus.Succeeded)
        {
            LoadAssets();
        }
        else
        {
            Debug.LogError("dependencyLoaded is Failed");
        }
    }

    private void LoadAssets()
    {
        AsyncOperationHandle<IList<GameObject>> handle = Addressables.LoadAssetsAsync<GameObject>(locations, OnAssetsCategoryLoaded);
        handle.Completed += OnAssetsLoaded;
    }
    private void OnAssetsCategoryLoaded(GameObject obj)
    {
        SpawnItem(obj.name);
    }
    private void OnAssetsLoaded(AsyncOperationHandle<IList<GameObject>> obj)
    {
    }

    void SpawnItem(string addressableKey)
    {
        if (!instantiated)
        {
            AsyncOperationHandle<GameObject> asyncLoad = Addressables.InstantiateAsync(myLabel, Vector3.zero, Quaternion.identity);
            StartCoroutine(progressAsync(asyncLoad));
            asyncLoad.Completed += AssetSpawned;
            instantiated = true;
        }
     
    }

    private System.Collections.IEnumerator progressAsync(AsyncOperationHandle<GameObject> asyncOperation)
    {
        float percentLoaded = asyncOperation.PercentComplete;
        while (!asyncOperation.IsDone)
        {
            Debug.Log("Progress = " + percentLoaded + "%");
            yield return 0;
        }
    }
    void AssetSpawned(AsyncOperationHandle<GameObject> obj)
    {
         Debug.Log("Asset Spawned");
}

The public method “initAddressables()” is called when I press a button.

Everything works fine at the first time. But when I try to load the same asset another time (without closing the application) it returns me this error:

ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: startIndex

And it happens when the application runs this line:

handle = Addressables.LoadContentCatalogAsync(catalogPath);

Is there a way to “reset” the addressables? Or something like that?

We’ll pass this along to the team for you. Could you tell us which version of the Editor you’re using, and which Package Manager version?

Unity 2019.2.6f1
Package Manager 2.2.0
Addressables 1.5.1

@lbaptista95 currently there’s not any supported way to do what you’re trying to do I don’t think. There is some discussion around changing how the catalogs are loaded and starting to track them so they can be unloaded. I can’t give any timeline, even a rough one, for something like that as I’m not sure when/if it’ll get picked up.

Go ahead and file a bug with Unity. This will make sure that we take things like this into account when sorting through our priorities.