Search Unity

Using local files while remote are being downloaded.

Discussion in 'Addressables' started by HugoClip, Jun 18, 2019.

  1. HugoClip

    HugoClip

    Joined:
    Feb 28, 2018
    Posts:
    52
    Imagine the following scenario.
    I have groupA with a bunch of .json files. This group/asset bundle is shipped with the binary and I take the following steps:

    1. Release the binary
    2. Update groupA (Build Content for update)
    3. User opens App
    4. App loads local groupA while remote groupA is being downloaded.

    Is step 4 possible? If so what's the correct way to do it? At the moment if I try to load anything from groupA, it will check that there is a newer asset bundle and I have to wait for the download to finish to use the files. Is there a way to put the remote catalog "on hold" or something similar?
     
  2. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    By default, your game code says Load("thing"), and the content catalog maps "thing" to an asset (in a bundle). So, upon launching the app, if a new catalog maps "thing" to something remote, addressables has no concept of using something else temporarily.

    So you need two things. "thing_local" and "thing_remote". Or more likely, two "thing" addresses with different labels. From there, you'd need to write your own addressables wrapper to handle a fallback system. It would check if the ideal asset is available, if not, load the fallback, while attempting to download the ideal.

    Once ideal is downloaded, you have another complexity. The easy solution is to do nothing until app restart (at which point ideal will show as ready). The harder solution is to change out things in your game to switch from fallback to ideal.
     
    danilonishimura likes this.
  3. HugoClip

    HugoClip

    Joined:
    Feb 28, 2018
    Posts:
    52
    I was hoping I could do that with some kind of custom provider. But that solution works for my case anyway.
    Thanks for the answer and for your time. Keep up the good work!
     
    unity_bill likes this.
  4. HugoClip

    HugoClip

    Joined:
    Feb 28, 2018
    Posts:
    52
    @unity_bill
    I have a question regarding your solution.
    Consider the following:

    I have a thing_remote which has a new version, lets call it version V2. So locally I have thing_remote V1, on this particular case, I don't want to load thing_local, since locally I have a newer shiny version of it, the thing_remote V1 that was already downloaded previously. Is there any API to check if I have an older version of thing_remote cached and use that bundle while downloading the thing_remote V2?

    I know that I could probably manually load it from the cache path, but that would kind defeat the purpose of using addressables. Do you have any suggestions?
     
  5. HugoClip

    HugoClip

    Joined:
    Feb 28, 2018
    Posts:
    52
  6. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    Once you get the new catalog, Addressables will have forgotten that "thing_remote v1" exists. So it'll see you have a local "thing_local" and a remote "thing_remote v2".

    The somewhat complex fix for you would be to have some save file with your game that was "remapped local stuff". What you could do is this:
    - on first launch, show "thing_local" and download "thing_remote v1"
    - once "thing_remote" existed for you (either post download, or on next launch), save some data that tells you that "thing_local" address actually maps to this remote v1 that's in your bundle cache.
    - Then each time you launch your app, after you've read the catalog, you remap "thing_local" from the actual local thing, to the cached bundle with "thing_remote v1". So while v1 is all that exists, both "thing_local" address and "thing_remote" address point to the same file.
    - then some day once a v2 exists, your system will download v2 while showing hte fallback of "thing_local". it just so happens that "thing_local" actually loads the cached "thing_remote v1".

    complex, but doable. I think.
     
  7. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464