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. Dismiss Notice

How to work with the addressables built with another project?

Discussion in 'Addressables' started by ArsenGamedev, Nov 13, 2019.

  1. ArsenGamedev

    ArsenGamedev

    Joined:
    May 18, 2017
    Posts:
    12
    Hi!
    I need some help with understanding how to do stuff in the addressables.
    I have two projects,
    the first with the sources of asset bundles and
    the second which uses the bundles built by the first project.

    Also, I have a list of all prefabs in each bundle, generated by the first project, which is used by the second project to realize where to get requested prefabs.

    Now I try to migrate the projects to the addressables and I have difficulties to figure out how to integrate the addressable list without related prefabs in the project. Is it even possible?

    So what are your ideas about it?
     
  2. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    736
    So what you'll need to do is make sure your project which uses the content built by Addressables has access to the catalog built by the project with the asset sources. You can load new catalogs at runtime with
    Code (CSharp):
    1. Addressables.LoadContentCatalogAsync(...)
    which should allow you to use the content catalog and data built with your other project.
     
    Scott_Pottenger likes this.
  3. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    736
    While testing in the Editor you won't be able to use Fast or Virtual mode for this, however. Just something to keep in mind.
     
  4. ArsenGamedev

    ArsenGamedev

    Joined:
    May 18, 2017
    Posts:
    12
    Thanks, I have managed to do what I needed.
    So I put here some details.
    First of all, I set the catalog build destination here
    upload_2019-12-4_14-10-48.png
    Then I built bundles and catalog by regular way
    upload_2019-12-4_15-16-24.png

    Then in the second project, I did this (code is complete dummy just for the demonstration)

    Code (CSharp):
    1.  
    2. void Start()
    3.     {
    4.         AsyncOperationHandle<IResourceLocator> loadContentCatalogAsync = Addressables.LoadContentCatalogAsync(  
    5.          @"d:\___adressables\catalog\catalog_2019.12.04.11.47.54.json");
    6.         loadContentCatalogAsync.Completed += OnCompleted;    
    7.     }
    8.  
    9.     private void OnCompleted(AsyncOperationHandle<IResourceLocator> obj)
    10.     {
    11.         IResourceLocator resourceLocator = obj.Result;
    12.         resourceLocator.Locate("belt_metalX.prefab", typeof(GameObject), out IList<IResourceLocation> locations);
    13.         IResourceLocation resourceLocation = locations[0];
    14.         GameObject resourceLocationData =(GameObject) resourceLocation.Data;
    15.         Addressables.InstantiateAsync(resourceLocation);  
    16.     }
    And I the gameobject was loaded to the scene.
     
  5. nauroman

    nauroman

    Joined:
    Nov 1, 2014
    Posts:
    13
    Thank you! It helps a lot.

    Small addition.

    It's not necessary to use
    resouceLocator.Locate


    After Content Catalog is loaded it is safe to use:

    Code (CSharp):
    1. Addressables.InstantiateAsync(assetAddress);
     
  6. bambamyi

    bambamyi

    Joined:
    Nov 26, 2008
    Posts:
    90
    Thank you for your insights. I was able to create an addressable bundle and category JSON file and moved the JSON file over to the codebase unity project.

    I can see that loading the category is working... and I can see the keys and all but I cannot load any assets after this... I have searched around and still stuck... I feel like I am missing something... any suggestions? I have moved the asset bundle that the content project created to a remote server and I see the remote server address in the JSON category file.

    Much appreciated!
     
  7. felix_Topgolf

    felix_Topgolf

    Joined:
    Dec 11, 2020
    Posts:
    3
    When I do this resourceLocation.Data is null :(
    do I need to wait for something ales to happen in between resourceLocator.Locate and collect the data?
     
  8. goneboy0623

    goneboy0623

    Joined:
    Jan 3, 2020
    Posts:
    2
    Im having the same issue. not sure whats happening here. ive been stuck on this for days and im starting to loose hope. upload_2021-3-24_17-52-27.png
     
  9. Digika

    Digika

    Joined:
    Jan 7, 2018
    Posts:
    225
    I just went through multiple similar threads, all with the same question expressed here and there is literally no answers. Daily reminder that Addressables was posed as a flexible universal solution to such approach. Think about it for a second.
     
  10. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,796
    Howdy all! I'll flag this with the team for a bit of guidance!
     
  11. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    736
    Hey all, just a couple of things to double check:
    1. Ensure that all AssetBundles from your second project are uploaded to your server.
    2. Make sure Addressable Groups in your second project aren't set to LocalBuild/Load paths
    3. Make sure that you have Build Remote Catalog turned on in your second project and that the remote catalog is the one you're loading in your main project. If you load the local catalog of the secondary project it's not going to work (without a very specific setup and likely a bit of manual copying AssetBundles)
    There isn't really any documentation about how to use multiple project setups because we originally didn't officially support it. I think we've added a few blurbs in the docs but we don't have any dedicated manual pages. We'll change this in the future and hopefully get some useful docs that explain how to use multiple project setups more clearly.

    And, as always, if you feel like what you're seeing is a legitimate bug please do file a bug with your project if you're at all able. A good project goes a long way to help us fix issues.
     
  12. EricBlanchard-Deleptual

    EricBlanchard-Deleptual

    Joined:
    Dec 28, 2014
    Posts:
    3
    Hey friends!

    I'm also trying to get a version of this to work correctly. I have a bunch of WebGL games that use Addressables, and they all work fine. What I'm trying to do is a build a config project that tests the time it takes to load up one of the Addressable scenes from the other projects. I'm starting a timer, loading the scene catalog asynchronously, waiting for completion, and then trying to download asset dependencies. However it keeps looking for the bundle at the URL from the config project, instead of from the URL where the newly loaded catalog is from. "configurl/assetpath" when instead I am looking for "newcatalogpath/assetpath". Is that possible to achieve?

    Cheers!
     
    unity_7zw9ebm9jBJwig likes this.
  13. nexcentric

    nexcentric

    Joined:
    Aug 3, 2020
    Posts:
    5
    Any update on this? Many thanks!!
     
  14. shibi2017

    shibi2017

    Joined:
    Jan 18, 2018
    Posts:
    153
    do you cahnge the line with "resourceLocator.Locate("Cube", typeof(GameObject), out IList<IResourceLocation> locations);" ?
    you should use your own Address(string) to locate.
     
  15. shibi2017

    shibi2017

    Joined:
    Jan 18, 2018
    Posts:
    153
    Hi, when I execute " Addressables.InstantiateAsync(resourceLocation);", I got error:
    Unable to open archive file: Library/com.unity.addressables/aa/Windows/StandaloneWindows64/6465c1a6ac1c936823b4e643669314df_unitybuiltinshaders_5a453e079aea0b5b1703241592334b62.bundle

    have you ever met this before?
    I use a remote server.
     
  16. shibi2017

    shibi2017

    Joined:
    Jan 18, 2018
    Posts:
    153
    Hi davidla!
    Can you explain how to set two project more detailed?
    I create 2 project and want Project A load Project B's Asset bundle on a Remote server.
    I can get the catalog but fails in InstantiateAsync().
    Console told me the file can not open:
    Unable to open archive file: Library/com.unity.addressables/aa/Windows/StandaloneWindows64/6465c1a6ac1c936823b4e643669314df_unitybuiltinshaders_5a453e079aea0b5b1703241592334b62.bundle

    I guess it's a problem with my settings, but I can not figure out where.
    Both Addressables settings turn on disable update catalog and build remote catalog.
    and all other setting are same.

    I try serveral different setting combination but no one works. error is same all the time.
     
  17. Kultie

    Kultie

    Joined:
    Nov 14, 2018
    Posts:
    48
    According to the path, it's seem that the bundle you want to load are marks as local bundle inside the addressable build. In order to load bundle from other project, every group must choose REMOTE LOAD PATH as the load path
     
  18. shibi2017

    shibi2017

    Joined:
    Jan 18, 2018
    Posts:
    153
    Thank you. but I try to make the Loading-Project's group all to remote load, but still happens, really confused.
    I'll try again.
    thanks again, love your cat!
     
  19. shibi2017

    shibi2017

    Joined:
    Jan 18, 2018
    Posts:
    153
    I figure out finally!
    When I'm in Loading-Project, I need to build Addressables Group(even it is empty in this project) to get into Play mode(Using Use Existing Builds Mode in addressables), and Unity did not create a AB file to Local Load Path( equals to Local Load Path).
    And When I want to load remote assets. it will first check the local ab file, if it doesn't exist, it will stop and give me an error.

    So solution, I copy the local ab file from Building-Project to Loading-Projcet, and it goes well(the file name is same).
     
  20. Kultie

    Kultie

    Joined:
    Nov 14, 2018
    Posts:
    48
    Glad that you've solved it.

    Yeah I didn't mention that the Project that you use to load from other project need to build the addressable too. I find this really confuse first time around.
     
  21. shibi2017

    shibi2017

    Joined:
    Jan 18, 2018
    Posts:
    153
    yeah, and after another some time to check it. I found a mistake I've made. If I build All groups in second project(I missed the default group before) to remote load and remote build, it should work without manully copy my bundle file to the first one.
    It's smooth and thanks to Unity.
    have a good day, Kultie.
     
  22. Kultie

    Kultie

    Joined:
    Nov 14, 2018
    Posts:
    48
    You better be mark your target group as Default Group (That what I did). Unity use Default Group to build all the builtin-stuff in your case it's builtin_shader. And also check for custom shader prefix to prevent some collide with other bundle(In the bundle group settings).
    Cheer!
     
  23. shibi2017

    shibi2017

    Joined:
    Jan 18, 2018
    Posts:
    153
    Thanks again Kultie. I'll go back to this thread and find your help if I met new problems.
    have a good day!
     
  24. DomeCreator

    DomeCreator

    Joined:
    Mar 5, 2020
    Posts:
    28
    Hi guys, I'm trying to load a scene and it doesn't work.

    Here's a part of the code I've made, resourceLocator always return false

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.AddressableAssets;                    // Needed to load addressable
    5. using UnityEngine.ResourceManagement.AsyncOperations;   // Needed to load asynchroniosly
    6. using UnityEngine.AddressableAssets.ResourceLocators;   // Needed to load new catalogue
    7. using UnityEngine.ResourceManagement.ResourceLocations; // Needed to load new catalogue
    8. using UnityEngine.ResourceManagement.ResourceProviders; // Needed to load scene
    9. using UnityEngine.SceneManagement;                      // Needed to load scene
    10.  
    11. public class LoadFirstScene : MonoBehaviour
    12. {
    13.     public static LoadFirstScene singleton;
    14.  
    15.     public AssetReference obj;
    16.     public string cataloguePath;
    17.     public string prefix;
    18.     public AssetReference sceneRef;
    19.  
    20.     private AsyncOperationHandle<SceneInstance> loadSceneHandle;
    21.  
    22.     void Awake()
    23.     {
    24.         if(singleton == null)
    25.         {
    26.             singleton = this;
    27.         }
    28.         else
    29.         {
    30.             Destroy(this);
    31.         }
    32.        
    33.     }
    34.  
    35.     // Start the load operation on start
    36.     void Start()
    37.     {
    38.         AsyncOperationHandle<IResourceLocator> loadCatalogue = Addressables.LoadContentCatalogAsync(cataloguePath, prefix);
    39.         loadCatalogue.Completed += OnCompleted;
    40.  
    41.         //StartCoroutine(UpdateCatalogs());
    42.     }
    43.  
    44.     private void OnCompleted(AsyncOperationHandle<IResourceLocator> catalogue)
    45.     {
    46.         IResourceLocator resourceLocator = catalogue.Result;
    47.  
    48.         foreach (var v in resourceLocator.Keys)
    49.         {
    50.             Debug.Log(">>>>>>>>>>>>>>>> " + v.ToString());
    51.         }
    52.  
    53.         if (resourceLocator.Locate("SampleScene.unity", typeof(Scene), out IList<IResourceLocation> locations))
    54.         {
    55.             IResourceLocation resourceLocation = locations[0];
    56.         }
    57.         else
    58.         {
    59.             Debug.LogError("resourceLocation wrong");
    60.         }
    61.     }



    Here's the debug I get (seems to load correctly the catalogue :
    upload_2022-4-13_10-22-21.png


    I don't understand what I've made wrong ?
    Any clue will be appreciated.
    Thx
     
  25. tytyka

    tytyka

    Joined:
    Sep 25, 2014
    Posts:
    2
    Try replacing typeof(Scene) with typeof(SceneInstance)
     
    _BlenMiner_ likes this.