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

Shared addressables assets

Discussion in 'Addressables' started by aurelien-morel-ubiant, Jul 29, 2019.

  1. aurelien-morel-ubiant

    aurelien-morel-ubiant

    Joined:
    Sep 27, 2017
    Posts:
    275
    Hello @unity_bill ,
    I have a really fast question :
    Is it possible to share addressables assets (catalog / group / etc...) between projects.

    Fast explanation :
    We have one project (app#1) with all our resources that will be used to generate addressables assets and bundles that we will upload on our server.

    Then in this app (app#1) and in another app (app#2 and maybe 3 etc...), I would to retrieve those assets without generating them twice (once per app cause it's not really useful cause it will be basically the same). Is it possible to do this with the current addressables system ?

    I can maybe embed the basic addressables stuff during the build phase of our app#2 to just have the link to the "true" bundles / assets generated in the app#1
     
  2. danilonishimura

    danilonishimura

    Joined:
    Jul 13, 2010
    Posts:
    70
    Yes but there's some gotchas. Here is how I did it:

    Project1 is the asset setup project, where I setup the addressables. In my case I configured it to publish to my local webserver to make it more like the final version which will fetch those assets from a webservice. This project doesn't (shouldn't?) need any game script, as it contains only the "view" aspect of those assets.

    Project2 has the game code. It doesn't need to have any art asset, because we load all assets from bundles, so this project is the "slim" code-only project. This project needs the Addressables package installed, but it doesn't need to be setup, you can remove the addressables folder from your project (Assets folder, not Package) in case you created it trying to make it work. From here, it's pretty straightforward. Initialize the addressables using Addressables.InitializeAsync, and then load the new catalog using Addressables.LoadContentCatalogAsync(catalogPath).

    The problem here is that you can't have AssetReferences as this would mean that you have to copy the Addressable Setup from the art project to this, making the whole process a lot more complicated. The way to get the assets is by loading them using their string key. Be sure to check if this bundle needs to be downloaded or has reference to other updated bundles by calling Addressables.DownloadDependenciesAsync(assetKey) before Addressables.InstantiateAsync(assetKey).

    The generated asset bundles probably have references to some built-in AssetBundles from your Project1 Library. You'll need to copy those bundles to your code Project2. They're usually at Library\com.unity.addressables\StreamingAssetsCopy\aa\[Platform]. Copy all those bundles to the same path on Project2. It's important to respect the platform folders. You can't use bundles built for one platform on another one. They must be built for that specific platform. If you're publishing to many platforms, be sure to copy all of them.

    Edit: If any of you guys found out a way to sync the list of keys, would be nice to share with us.
     
    Last edited: Jul 29, 2019
  3. mikaelK

    mikaelK

    Joined:
    Oct 2, 2013
    Posts:
    281
    Hi, @danilonishimura
    Thanks your post helped a lot.

    What do you mean with sync the keys?
    The only thing I had to do was to build catalog and bundles to location, then from project b
    load the catalog and go through the keys. Did not have to copy files, so might be that something has changed.

    So I'm looking at the catalog file and I can print the content with the code:

    Code (CSharp):
    1. foreach(var resourceLocator in Addressables.ResourceLocators){
    2.     foreach(var key in resourceLocator.Keys){
    3.         Debug.Log(key);
    4.     }
    5. }
    You can use these keys to load content built from project A
     
  4. danilonishimura

    danilonishimura

    Joined:
    Jul 13, 2010
    Posts:
    70
    @mikaelK
    Oh I figured that out shortly after and forgot to go back here and mention it. Thanks for providing the code ;)
     
  5. Magic73

    Magic73

    Joined:
    Jun 23, 2015
    Posts:
    127
    @danilonishimura I'm having some issue with sharing addressables.
    Using a "producer" project, I uploaded my catalog+bundles files into my website.

    Now, from a new Unity project, I'm trying to load them.
    you wrote that I may remove the addressables folder from your project, but doing this, I got this exception:

    Code (CSharp):
    1. TargetException: Non-static method requires a target.
    2. System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <9577ac7a62ef43179789031239ba8798>:0)
    3. System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <9577ac7a62ef43179789031239ba8798>:0)
    4. UnityEngine.AddressableAssets.AddressablesImpl.InitializeAsync (System.String runtimeDataPath, System.String providerSuffix, System.Boolean autoReleaseHandle) (at Library/PackageCache/com.unity.addressables@1.16.16/Runtime/AddressablesImpl.cs:413)
    5. UnityEngine.AddressableAssets.AddressablesImpl.InitializeAsync () (at Library/PackageCache/com.unity.addressables@1.16.16/Runtime/AddressablesImpl.cs:433)
    6. UnityEngine.AddressableAssets.Addressables.InitializeAsync () (at Library/PackageCache/com.unity.addressables@1.16.16/Runtime/Addressables.cs:342)
    7. SyncAddressables.Init () (at Assets/Scripts/SyncAddressable.cs:23)
    8.  
    when I run :
    Code (CSharp):
    1. Addressables.InitializeAsync()
    If I create an addressable settings, then the Init goes on without any exception, but then I don't understand how to load a new catalog.

    When I call this:

    Code (CSharp):
    1. Addressables.LoadContentCatalogAsync("https://website/catalog_2021.03.24.23.02.14.json")
    it doesn't load it. unity look into local folders.
    then I changed the addressable settings of the project, setting them like the "producer" one.

    but it doesn't work. may you give some more info about?
     
  6. Digika

    Digika

    Joined:
    Jan 7, 2018
    Posts:
    225
    Can you elaborate on that? Is it just Textures, Materials, Meshes and Shaders and they are composed only with default Unity Script components (Animator, Sprite Rendered, etc? If so, what the point exactly of using addressables here?

    How are you now managing these prefabs to add code components? Did you reinvent whole custom monoscript serialization system and deserialize, attach and initialize them at runtime on your own? That seems even more work and error prone then it was worth to begin with.
     
    AdminXRBASE likes this.