Search Unity

Question Assign Addressable download path during runtime

Discussion in 'Addressables' started by JonBFS, Dec 12, 2020.

  1. JonBFS

    JonBFS

    Joined:
    Feb 25, 2019
    Posts:
    39
    I want to assign a URL for Addressables to fetch assets during runtime and point it to my Amazon S3 server, but I don't know which option (or neither) to take.

    --------------------
    OPTION 1
    1. Generate all bundles including catalog json & hash file using Unity Cloud and upload them to my S3 bucket.
    2. Build the app with my Addressables profile's LoadPath set to a static variable {AB.AssetBundleURL.RemotePath} (Namespace.Class.Method)
    3. Call my API to get the path of my S3 bucket where my asset bundles live and assign it to the static variable. ex. https://bucketname.s3-ap-northeast-1.amazonaws.com/ver1/iOS
    4. Initialize Addressables.

    OPTION 2
    1. Generate all bundles including catalog json & hash file using Unity Cloud and upload them to my S3 bucket.
    2. Call my API to get the path of my S3 bucket where my asset bundles live and assign it in the TransformInternalId callback.

    Code (CSharp):
    1. Addressables.InternalIdTransformFunc = (location) => {
    2.    //Implement a method that gets the base url for a given location
    3.    string baseUrl = GetBaseURL(location);
    4.  
    5.    //Get the url you want to use to point to your current server
    6.    string currentUrlToUse = GetCurrentURL();
    7.  
    8.    return location.InternalId.Replace(baseUrl, currentUrlToUse);
    9. };
    3. Finally initialize Addressables.
    --------------------

    Which one is seen as better and why? And will bundles downloaded this way be cached automatically so that a user won't have to be online after having downloaded the bundles? I feel like I might be missing something
     
  2. JonBFS

    JonBFS

    Joined:
    Feb 25, 2019
    Posts:
    39
    I ended up taking option 1 and it works!

    Something to be careful of
    * Don't build your app and addressables in separate configs in Unity Cloud. The hashes will not match!