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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Mesh in an Addressable object missing after Addressable.release

Discussion in 'Addressables' started by zhouhong, Apr 26, 2022.

  1. zhouhong

    zhouhong

    Joined:
    Jul 5, 2017
    Posts:
    5
    I have built two catalogs with a object prefab in each and put them in server folders. I run a new Unity project and try to instantiate that two object prefabs, so I load first catalog and get the object instantiated then continue to load 2nd catalog but fail to load the 2nd object. I then add Addressable.release after the first object instantiated and 2nd object can be loaded and instantiated, but all the meshes in the first object instance gone.

    Anyone has idea to solve this problem? or it is just impossible to load objects from different catalog?

    Thanks.
     
  2. pillakirsten

    pillakirsten

    Unity Technologies

    Joined:
    May 22, 2019
    Posts:
    346
    Hi @zhouhong it is possible to load different catalogs using LoadContentCatalogAsync: https://docs.unity3d.com/Packages/c...Distribution.html#loading-additional-catalogs. Once the catalogs are loaded, you can load objects referenced by any of the catalogs.

    Addressables.Release will unload any objects associated with the asynchronous operation handle, so I would not call Release on the first object's loading operation until the object is ready to be removed.
     
  3. zhouhong

    zhouhong

    Joined:
    Jul 5, 2017
    Posts:
    5
    Hi @pillakirsten Thanks for the reply. I have tested working fine with just one catalog downloaded from my server. While trying to get the object from second catalog after the first object instantiated, actually, error is not at LoadContentCatalogAsync but at LoadAssetAsync, see the code below:
    Code (CSharp):
    1.  
    2. ...
    3.     IEnumerator LoadObjectLocation(string label)
    4.     {
    5.         AsyncOperationHandle<IList<IResourceLocation>> handle = Addressables.LoadResourceLocationsAsync(label);
    6.         yield return handle;
    7.         Debug.Log(handle.Result);
    8.         IList<IResourceLocation> unLoadedLocations = handle.Result;
    9.         Addressables.Release(handle);
    10.         Debug.Log("UnloadedLocation = " + unLoadedLocations.Count);
    11.         foreach (var location in unLoadedLocations)
    12.         {
    13.               ...  
    14.              ObjectLocations.Add(location);
    15.         }
    16.         totalObjects = ObjectLocations.Count;
    17.         for (int i = 0; i < totalObjects; i++)
    18.         {
    19.             Debug.Log("TotalObjectLocation = " + ObjectLocations.Count);
    20.             IResourceLocation location = ObjectLocations[i];
    21.             Debug.Log(ObjectLocations[i].Data);
    22.             Debug.Log(location.Data);            GameObject resourceLocationData = (GameObject)location.Data;
    23.             AsyncOperationHandle<GameObject> loadAssetAsync = Addressables.LoadAssetAsync<GameObject>(location);
    24.  
    25.             loadAssetAsync.Completed += StartToSpawn;
    26.         }
    27.     }
    28.  
    29.     private void StartToSpawn(AsyncOperationHandle<GameObject> obj)
    30.     {
    31.             Debug.Log(obj.Result);
    32.         GameObject resourceLocator = obj.Result;
    33.         GameObject go = Instantiate(resourceLocator);
    34.         StartCoroutine(GetNext(obj));
    35. }
    36.     IEnumerator GetNext(AsyncOperationHandle<GameObject> obj)
    37.     {
    38.         yield return new WaitForSeconds(5);
    39.         ObjectLocations.Clear();
    40.         LoadObjectLib();//start loading the 2nd catalog
    41.     }
    42.  
    43. ...
    When spawning the 2nd object, then error is here:
    Exception encountered in operation Resource<GameObject>(xxxx.prefab): Unable to load asset of type UnityEngine.GameObject from location Assets/MyPrefabs/xxxx.prefab.
    UnityEngine.AsyncOperation:InvokeCompletionEvent ();
    ArgumentException: The Object you want to instantiate is null.
    ...
    so I believe now must be some code wrong here. The strange thing is:
    1. Debug.Log(ObjectLocations.Data) and Debug.Log(location.Data) both returns Null even in first object loaded. is it loading from cache which I don't want that?
    2. the unLoadedLocations.count returns 2 when LoadObjectLocation(string label) being run for 2nd time, what I created just one object in each catalog, it should return 1 here. but it seems add up to the first one.

    thanks again for spending time to read my code, I really need some helps.
     
  4. zhouhong

    zhouhong

    Joined:
    Jul 5, 2017
    Posts:
    5
    AsyncOperationHandle<GameObject> loadAssetAsync = Addressables.LoadAssetAsync<GameObject>(location)
    it keeps looking for the object in 2nd catalog from the IResourceLocation of 1st catalog, thus fail. how to refresh the location without release the handle of 1st object? I want to keep the 1st Object instance