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

Load addressables from custom URL

Discussion in 'Addressables' started by Makkus, Apr 8, 2020.

Thread Status:
Not open for further replies.
  1. Makkus

    Makkus

    Joined:
    Sep 14, 2015
    Posts:
    20
    Brief question (because I didn't find any information on this):
    Is is possible to load addressable assets from runtime deployed URL (i.e. not known during build time)? Like it can be done with AssetBundles (load bundle from url string)?
    I feel like one might need to implement a custom ResouceProvider or something like this? But I find it hard to get information and examples of the Addressables API (the API doc is really minimal, I would say). I need to decide if I stick with using AssetBundles or rather go for addressables. But for my game it would be quite crucial to be able to load assets from customizable URL after deploy.
     
  2. jipsen

    jipsen

    Joined:
    May 22, 2018
    Posts:
    37
    Yes, you can load from a custom URL. Check out badgerdox videos on Addressables and instead of hosting on google cloud, etc, just use your own URL with https instead.
     
  3. Makkus

    Makkus

    Joined:
    Sep 14, 2015
    Posts:
    20
    Definitely good (and important) tutorials, but still all remote paths are defined during player build. What I am looking for is this: I've got a server which can send a URL along with a (list) of addressable names. I now want the player to load the addressables hosted on the location the player recieved. Or in pseudocode:
    Code (CSharp):
    1. Addressables. LoadFromUrl(Url myCustomUrl, string[] addressablesNames)
    Basically an addressables equivalent to:
    Code (CSharp):
    1. UnityWebRequestAssetBundle.GetAssetBundle(someUrlString);
    Can this be achieved with addressables?
     
    RRD123 and Julien-Lynge like this.
  4. Julien-Lynge

    Julien-Lynge

    Joined:
    Nov 5, 2010
    Posts:
    142
    I've got the same question:

    We're planning to run a copy of the unity editor headless in the cloud to process 3d models and turn them into (presumably) asset bundles. We then want to load them (and manage the memory) with the Addressables system. However, the documentation is a bit lacking.

    It looks like what we want to do when we want to load an asset is to create an AssetBundleProvider, which is a type of IResourceProvider. We can then pass that to LoadAssetAsync<TObject>(IResourceLocation location).

    So the question is: how do we programmatically create an AssetBundleProvider given a URI and all the other info we have?

    I tried looking through the source code starting with LoadAssetAsync<TObject>(IResourceLocation location), and it got pretty confusing around ResourceManagement.ProvideResource(IResourceLocation location, Type desiredType = null).

    I'll continue to try to figure this out by reading the code, but if anyone already knows how to do this, I'd love to hear from you!
     
  5. Julien-Lynge

    Julien-Lynge

    Joined:
    Nov 5, 2010
    Posts:
    142
    Alright, as a follow-up, here's what I've learned:

    This thread has lots of great info and a working example of creating a catalog for your single asset, and then first loading a catalog, and then loading the asset that was created in another project:
    https://forum.unity.com/threads/gen...parate-project-for-multiple-platforms.567151/

    That's a workable solution; however, I'd like to just be able to load the asset directly based on a known url. I don't want to have to generate catalogs for each asset, and I don't want to have to make 2 web requests to download the asset. However, their solution was incredibly valuable: just being able to step through all the steps based on their example has allowed me to figure out what you need to do.

    At the end of the day, you don't actually need to build a full catalog for your asset bundle. You can just build a ContentCatalogData.CompactLocation object. (Note: this class is private, so you can't access it directly. You can either copy it to a new class, or you can use reflection to create an instance of it.)

    Here's an example showing how you can figure this out. To run this example, follow the instructions on the link above to generate your catalog. Then, attach the catalog as TextAsset json.

    Code (CSharp):
    1.        ContentCatalogData contentCatalogData = JsonUtility.FromJson<ContentCatalogData>(json.text);
    2.         var resourceLocationMap = contentCatalogData.CreateLocator();
    3.         resourceLocationMap.Locate("armchair", typeof(GameObject), out IList<IResourceLocation> locations);
    4.         Debug.Log("Resource location is a: " + locations[0].GetType());
    5.         Addressables.LoadAssetAsync<GameObject>(locations[0]);
    So all you really need here is locations[0] - you could skip all the rest. The next question is: what data in that object do you actually need? E.g. what is the smallest amount of data you need to give the Addressables system for it to load an asset bundle from a URL, and still get all the benefits of caching, version control, etc. - if you want those things?

    I'm working on that now, and my guess is: not much. A lot of what you find in CompactLocation is standard data - you could just pre-create a reusable CompactLocation object, then fill in a couple fields each time you want to use it to load an assetbundle.
     
    Last edited: Jun 3, 2020
Thread Status:
Not open for further replies.