Search Unity

Instantiate objects from remote catalog

Discussion in 'Addressables' started by unnanego, Jan 14, 2021.

  1. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    199
    How do you do this? The docs just state that you can and doesn't provide any more info. I've tried everything I could, I have no idea how to do this. Oh, and I need this without knowing the actual keys, because I won't know the contents of the catalog beforehand - the content will be created by our clients.
     
  2. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    199
    anyone? It kinda is the most important feature of the system and not a single mention anywhere on how to do this...
     
  3. MartinTwinDrums

    MartinTwinDrums

    Joined:
    Jan 18, 2021
    Posts:
    14
    First, you need to make sure that you are exporting your addressables with Build Remote Catalog active and the Load Path being correctly set up (here e.g. I am loading my addressable assets from the stream assets folder).

    upload_2021-1-18_13-35-43.png

    In the export folder you will find the catalog json and the corresponding asset bundles. Move them to the load path location and then you can do something like that:

    Code (CSharp):
    1.     public class LoadAdddresableAssetBundle : MonoBehaviour
    2.     {
    3.         private string catalogPath => Path.Combine(Application.streamingAssetsPath, "StandaloneOSX/catalog_2021.01.01.12.46.05.json");
    4.  
    5.         private IEnumerator Start()
    6.         {
    7.             Debug.Log("Loading catalog from " + catalogPath);
    8.             var asyncOperation = Addressables.LoadContentCatalogAsync(catalogPath, true);
    9.             yield return asyncOperation;                
    10.             Debug.Log("Loading done");
    11.             Addressables.InstantiateAsync("kuvutuka-static-clean/sector/main").Completed += (obj) =>
    12.             {
    13.                 var sector = obj.Result.gameObject.GetComponent<Sector>();
    14.             };
    15.             // yield return Addressables.LoadSceneAsync("Assets/Scenes/Mbuta_Island/Mbuta-Static-NoScripts.unity", LoadSceneMode.Additive, false);        
    16.         }
    17.     }
    You can find more information in the documentation:
    https://docs.unity3d.com/Packages/c...ContentCatalogAsync.html?q=LoadContentCatalog
     
    Last edited: Jan 18, 2021
    unnanego likes this.
  4. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    199
    The whole point of this - I can't know the keys beforehand! The client will control the models himself by uploading/deleting the catalog and bundle files. How do I get the keys from the remote catalogue?
     
  5. MartinTwinDrums

    MartinTwinDrums

    Joined:
    Jan 18, 2021
    Posts:
    14
  6. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    199
    Which doesn't work - gives an exception on each of them. They are the names of the files, not keys + there are in this array a lot of shaders and all the scenes from the project (which are not marked as addressables) and even plain numbers (starting from 0) - I've tried all the options I could find - I failed to instantiate anything
     
  7. MartinTwinDrums

    MartinTwinDrums

    Joined:
    Jan 18, 2021
    Posts:
    14
    Works for me. Be aware that assets in the Resources folder and dependencies also get packed. If your default group is not also enabled for remote build most things will not load. Also: setting up the correct loading paths can be tricky.
     
  8. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    199
    ok, thanks, will try again