Search Unity

Load Addressables remotely from a second project without importing the content.

Discussion in 'Addressables' started by SReplyR, Apr 5, 2019.

  1. SReplyR

    SReplyR

    Joined:
    Jan 4, 2019
    Posts:
    12
    Hi,
    With assetbundles and a lot of pain, we were able to completely split the content in different projects, to build the bundles in each separated project and to load them on request in the built application without having the content ever touching the main project directly (as everything would be spawned and executed in runtime),

    I´m trying to get the same result with the Addressables to simplify a lot the reference management, but unluckily i´m missing how my main project should be informed about the address and the groups which would (in this case) created on the content project.

    I did setup the AddressableAssetSettings on the main project correctly (tested) but naturally Unity has no idea how to proceed, not having any group specified, being the content not there.

    What am i missing in the docs or in the description of the feature?
    Thanks in advance!
     
    erenaydin, mandisaw and jterry like this.
  2. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
  3. SReplyR

    SReplyR

    Joined:
    Jan 4, 2019
    Posts:
    12
    Thanks Bill,
    meanwhile i think i passed through that page a thousands of time already, without any good result unluckily. I had to manually copy the catalog, i´m not even sure anymore of what i did, but i was able to load the file and read it through that call. Then i guess a lot more should happen which normally is automatically triggered, meanwhile the time i had expired and i had to move to something else.

    But i will try again i guess, and this trial and error was anyways good to understand way more what´s under the hood of the feature.
     
    MurphyMurph_21 likes this.
  4. SReplyR

    SReplyR

    Joined:
    Jan 4, 2019
    Posts:
    12
    So!

    Apparently i did it, this is only the first step, but it felt really good to see the object appearing in Unity!

    A small guide for the first steps:

    1) Create your own content in a Unity project
    2) Create the Addressables in the way you want to have them and specifying in the RemoteBuildPath the path where you will host your Addressables. You will have to set this path on each group of the Addressable because this will be reflected in the json files and won´t work if not set.
    3) Build the Addressables and copy the files produced in the remote server specified
    4) Open a new project or your main project
    5) Copy/paste manually the settings.json and catalog.json from your content project "Assets/StreamingAssets/aa" to the main project one

    Code (not tested if everything is really needed but it works)


    Code (CSharp):
    1.  
    2. void Start()
    3.     {
    4.         Addressables.Initialize();
    5.         Addressables.LoadAsset<GameObject>("AssetAddress").Completed += OnCompleted;
    6.     }
    7.  
    8.     private void OnCompleted(IAsyncOperation<GameObject> obj)
    9.     {
    10.         Instantiate(obj.Result);
    11.     }
    6) Attention: before starting, make sure to enable the Addressables in the main project creating an Addressable Settings and specify Packed Play Mode, or you might get the Virtual or the Fast Mode and it won´t work.

    7) Maybe it´s obvious but just as a reminder: if you have any custom logic in the Addressables loaded, you will still have to manually copy the scripts attached for Unity to be able to get a reference to them.
     
    Last edited: Apr 17, 2019
  5. MartinAdcada

    MartinAdcada

    Joined:
    Jan 24, 2020
    Posts:
    6
    Hey, @unity_bill can you provide us with updates regarding this case?
    It's nearly one year ago since the last post?

    In our case, this is a very crucial topic.

    Thanks in advance,

    Martin
     
  6. loopzilla

    loopzilla

    Joined:
    Feb 16, 2015
    Posts:
    2
    I think "Addressables" system is dead.
    The initial goal of the system was to substitute old "SteamingAssets" system (that actually worked).
    A new design, is horrible. Nothing is clear. It seems like Unity devs incredibly over-complicated this system.
    And now, you just simply cant load bundle manually. Everything is doing this totally undocumented black box.

    I was trying to make separation between projects: project for progs, project for art. Because progs don't need reimport/download art assets, potentially it can be gigs of small files. I was spending hours to understand what the f**ing files I should download from Library folder. That is actually an internal folder for unity. I tried to load this hacky file catalog.json using Addressables.LoadContentCatalogAsync which is in this Library folder.
    And its totally have no information from what bundle it should load keys. Nothing is working. One simple and very important scenario is just impossible. I'm so angry to designers of this system. It looks like designers are solving own intended problems with patches and upgrades and totally not listen to real devs with their simple needs.
     
    Last edited: Jul 27, 2020
  7. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    513
  8. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Sorry for necro, but I stumbled upon this and LoadContentCatalogAsync seems exactly like what I'd need for my project.
    However I'm not very well-versed in Addressables yet and while building a little test project to try this out I'm getting stuck with the documentation not really helping me.

    I've made a little side project with an addressable bundle marked for remote building and built this.
    This bundle contains a single Sprite Texture with a simple address.
    Then in my main project I've created a script using LoadContentCatalogAsync which should be able to load this built bundle in.
    However, I have no clue what to actually use as a path. I'm assuming a web-address to wherever I'm eventually going to host the built content? What should I use as long as I'm working locally? Direct folder paths?

    On a more tricky note, suppose I have multiple bundles stored in that location, and some of these bundles might have assets with the same address within them, how would I be able to specify which bundle's asset I want to load at runtime?
    For example: bundle 1 contains an image addressed as img_1, and bundle 2 contains a different image with the same address. Both catalogs have been loaded. How can I specify which image I want from either bundle?
     
  9. IsaacLe

    IsaacLe

    Joined:
    May 13, 2021
    Posts:
    2
    I tried to use Addressables.LoadContentCatalogAsync to load a secondary catalog, but the assets still load from the old (default) catalog, I don't know if the secondary catalog could overwrite the old one or not, or I need to do any action to wipe out the old catalog data.
     
  10. sabin

    sabin

    Joined:
    Nov 24, 2012
    Posts:
    35
  11. SavedByZero

    SavedByZero

    Joined:
    May 23, 2013
    Posts:
    124
    This is stumping me also. Everything I could find suggests that all we need to do is A) build the addressable content to some local path (done), B) upload that bundle file to wherever we want to store it remotely -- say, our dreamhost server (done) C) make sure to put the url of that location in the remote loading path for our active group (or profile), at which point we should be able to pull and use it in any scene that uses the same Addressable loading code we have set up to load these files as if they were local.

    I've done all this, but when I delete the local copy of the addressable files, it still looks for them there and gets confused when it can't find them, even with the load path set to "RemoteLoadPath" with the url I uploaded the bundle to.
    The documentation didn't help me much either -- I find it very hard to wade through the information overload to find what I'm looking for.
     
    Last edited: Oct 4, 2022
  12. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    Hey all, this is the doc page we have to help with this workflow https://docs.unity3d.com/Packages/com.unity.addressables@1.20/manual/MultiProject.html

    The basics of it are:
    You have your source project (project A) and your content project (project B)
    Project A still has to build Addressables, but it can be basically empty. It just needs the initialization and runtime settings data
    Project B builds remote Groups like normal - the catalog needs to point to remotely accessible locations.
    Upload the AssetBundles and content catalog from Project B to your CDN
    In Project A, make sure you call the LoadContentCatalogAsync with the url of your remote catalog you built from from Project B
    From there it should work as normal.

    I hope that helps
     
  13. The_Pied_Shadow

    The_Pied_Shadow

    Joined:
    Jul 25, 2018
    Posts:
    14
    Alright, I got this working and wrote up a tutorial that I hope will help anyone doing this as well. This is for setting up two projects from scratch. I can't promise this works for everyone's specific needs, or that it's even all necessary for it to work, but hopefully it at least can be modified to suite your needs.

    Terms
    Primary Project - The project which contains code and from which the application is built from.
    Secondary Project - The project containing addressable assets which are built to a remote directory for the Primary Project to reference.
    Load Path - The location the addressables from the secondary project will be built to and loaded from.

    Setting Up Primary Project
    1. Install Addressables package
    2. Navigate to Window > Asset Management > Addressables > Groups
    3. Click "Create Addressables Settings"
    4. Click the "Play Mode Script" drop down and select "Use Existing Build (Windows)"
    5. Navigate to Window > Asset Management > Addressables > Profiles
    6. Create a new profile or use the default one
    7. Right click on the profile and click "Set Active"
    8. Change the "Remote" Bundle Location to "Custom"
    9. Change the "Remote.LoadPath" to your Load Path
    Setting Up Secondary Project
    1. Install Addressables package
    2. Navigate to Window > Asset Management > Addressables > Groups
    3. Click "Create Addressables Settings"
    4. Click the "Play Mode Script" drop down and select "Use Existing Build (Windows)"
    5. Navigate to Window > Asset Management > Addressables > Profiles
    6. Create a new profile or use the default one
    7. Right click on the profile and click "Set Active"
    8. Change the "Remote" Bundle Location to "Custom"
    9. Change the "Remote.LoadPath" and "Remote.BuildPath" to your Load Path
    10. Navigate to Window > Asset Management > Addressables > Groups
    11. Repeat steps 12 to 14 for every Addressable Group you want to build to the Load Path
    12. Select the desired group
    13. In the inspector, under "Content Packing & Loading" set the "Build & Load Paths" to "Remote"
    14. In the inspector, under "Content Update Restriction" set the "Update Restriction" to "Can Change Post Release"
    15. In the inspector, click "System Settings" to open the addressable settings
    16. Under Content Update, enable "Build Remote Catalog"
    17. Set "Build & Load Paths" to "Remote"
    18. Now every addressable in the configured groups will build to the Load Path when you select "Build" > "New Build" > "Default Build Script" in the Addressable Groups window.
    Loading Addressables From Primary Project

    The primary project must load the content catalog of the secondary project. This is done at runtime. Refer to the following example code which should be executed at the start of the application (or at least before you attempt to load any addressables from the remote location). The "UpdatePath" value should be your Load Path you set as the remote build and load for the projects.

    (Following codes uses System.IO, UnityEngine, UnityEngine.AddressableAssets, UnityEngine.AddressableAssets.ResourceLocators, and UnityEngine.ResourceManagement.AsyncOperations)

    Code (CSharp):
    1. string contentCatalogPath = "";
    2. var files = Director.GetFiles(updatePath);
    3.  
    4. foreach (string file in files)
    5. {
    6.      string[] splitFileName = file.Split(".");
    7.      string fileExtension = splitfileName[splitFileName.Length - 1];
    8.      if (fileExtension == "json")
    9.      {
    10.           string finalPath = file;
    11.           finalPath = finalPath.Replace(@"\", "/");
    12.           contentCatalogPath = finalPath;
    13.      }
    14. }
    15.  
    16. if (contentCatalogPath == "")
    17.      yield return null;
    18.  
    19. AsyncOperationsHandle<IResourceLocator> handle = Addressables.LoadContentCatalogAsync(contentCatalogPath, true);
    Once this code is executed in runtime, addressables from the secondary project can be loaded like normal during runtime such as with "LoadAddressableAsync".

    Good luck!

    P.S. I've seen an error where it fails to load the unity default shader bundle. This is because the bundle name is hashed and so the name is different between the two projects which the prefabs from the secondary project looking for the wrong bundle. Right now, I get around this by copying the bundle that is generated on a project build in the secondary project to the build of the first project (resulting in two shader bundles). If you see this error, it will show the file path to these files.
     
    Jribs likes this.
  14. Midiphony-panda

    Midiphony-panda

    Joined:
    Feb 10, 2020
    Posts:
    243
    Is it necessary to use the Play Mode "Use existing build" on the primary project ?

    I'm worried it forces the user to build the Addressables regularly on the primary project, AND target Windows platform (cannot target the editor to other platforms, like mobile).