Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

How to fetch latest catalog and re-initialize Addressables in runtime?

Discussion in 'Addressables' started by Kichang-Kim, Aug 7, 2018.

  1. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    493
    Hi. Is there any API for force refreshing the catalog to retreive latest assets from remote server?

    Here is detail:

    In mobile environment, users somtimes leave their device for a long time while game app is runnig on background. So when they re-activate game app, its local catalog cache may be different to server's latest asset on CDN. In this case, game app needs to detect asset catalog change and re-download catalog and assets.

    Also if above API is available, what happened when the asset which is loaded to memory is updateted on server? should I manually release all assets and re-load it manually?
     
    amaike likes this.
  2. unity_bill

    unity_bill

    Unity Technologies

    Joined:
    Apr 11, 2017
    Posts:
    999
    In theory you could look through our initialization code and cobble together something that would do this, but I wouldn't recommend it for anyone other than very advanced users. Dealing with all the ref-counting, loaded or not loaded assets, and loaded or not loaded catalogs gets fairly complicated.
    We are aware that this situation happens, but haven't spent much time on it yet. Odds are the general use case will have to involve relaunching the app, but that has more to do with how the user manages their data.

    -Bill
     
  3. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    493
    @unity_bill
    Thanks for reply. I think Addressables needs two API at least for production environment, because this situation quite happens in the mobile game.

    1. Catalog hash check : Check whether local catalog hash and remote catalog hash are same. Using this API, app can show dialog like "Game data is changed, You need to re-launch app.". or if restart API is available (see below), "Game data is updated, app will be restarted automatically." by using that API and changing current scene to first scene.

    2. Restart Addressables, including unload all loaded assetbundles and clear all reference count to zero. (also clear all internal object pools) : This needs because Unity does not provide app re-launching feature.

    With these features, I can move my in-house asset management system to Addressables :)
     
    amaike likes this.
  4. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    493
    @unity_bill
    Hi, is there any information about this features? I checked latest (0.3.5) Addressables's source code then found that this features can be implemented by adding force-refreshing flag to Addressables.Initialize().

    From
    Code (CSharp):
    1. public static IAsyncOperation<IResourceLocator> Initialize()
    2. {
    3.     if (s_initializationOperation != null)
    4.         return s_initializationOperation;
    5.  
    6.     ...
    7. }
    To
    Code (CSharp):
    1. public static IAsyncOperation<IResourceLocator> Initialize(bool forceRefresh = false)
    2. {
    3.     if (s_initializationOperation != null && !forceRefresh)
    4.         return s_initializationOperation;
    5.  
    6.     ...
    7. }
    Of course, other event-registrations should be carefully handled, like

    SceneManager.sceneUnloaded += OnSceneUnloaded;


    By allowing this API, developer can handle runtime-changed assets without restarting application. Dealing with ref-count, loading assets and internal running operations is doesn't matter because the purpose of this method is re-initialization, so simply destroying all internal state (ref count, assets, catalogue and operations ...) is enough.

    Also, catalog hash check can be implemented by comparing remote-hash (catalog_XXXX.hash on server) and local hash. Although this can be implemented by developer, officailly supported API needed because that internal Addressables's implementations can be changed in future.

    Thanks.
     
    Atlantiss and amaike like this.
  5. unity_bill

    unity_bill

    Unity Technologies

    Joined:
    Apr 11, 2017
    Posts:
    999
    No update on this yet. You are correct that the `forceRefresh` flag could trigger a new initialization, but just doing that will cause all sorts of issues if the game has already started loading things. This is not a straightforward feature to create, but I agree that it is useful, and is on our list.
     
  6. AceEX7

    AceEX7

    Joined:
    Feb 2, 2014
    Posts:
    11
    @unity_bill any updates about fetching the latest catalog at runtime?
     
  7. yoshitaka-arishima

    yoshitaka-arishima

    Joined:
    Jul 8, 2019
    Posts:
    5
    Our mobile game project also needs these APIs. Without these APIs, we cannot use Addressables.
    We want you to implement these APIs as soon as possible.
     
    mikito-wp and amaike like this.
  8. unity_bill

    unity_bill

    Unity Technologies

    Joined:
    Apr 11, 2017
    Posts:
    999
    Number one should be fairly straightforward for you to add yourself. You can just trigger a download of the remote hash.

    Number two is a bit tougher. Still doable in your own code, but this is the larger task we are looking at ways to solve ourselves.

    In the interim, I definitely encourage you to tweak addressables to meet your needs. This tool will often not solve all problems for a large game without some small tweaks. For large production games, addressables will often be a framework that devs can build customization on top of.
     
    amaike likes this.
  9. amaike

    amaike

    Joined:
    Mar 6, 2014
    Posts:
    8


    I am suffering from the same problem. I strongly hope that the APIs will be implemented.
     
    mikito-wp likes this.
  10. mikito-wp

    mikito-wp

    Joined:
    Nov 15, 2018
    Posts:
    1
    Without the re-initialization API, I think it is impossible that adopt Addressables in most mobile gaming projects using remote assets...

    It ’s a very important feature.

    I think if there is no problem with destructive re-initialization if the developer manages the timing tightly.
     
  11. GfoxBackflip

    GfoxBackflip

    Joined:
    Aug 28, 2017
    Posts:
    2
    @unity_bill Any news on either of these features? The ability to reinitialize addressables and potentially retrieve a new remote catalog without restarting the game is an incredibly important feature for all our mobile products.

    We managed this when we wrote our own asset management around asset bundles but we've moved over to addressables for newer products and now have no ability to push new content to someone who keeps their app running. Telling the user to restart the game is an unacceptable solution.
     
  12. unity_bill

    unity_bill

    Unity Technologies

    Joined:
    Apr 11, 2017
    Posts:
    999
    Totally missed adding this to the changelog (oops!) but we did add two APIs for this scenario to 1.3.3 - CheckForCatalogUpdates() and UpdateCatalogs().

    They don't reinitialize things, but they'll allow you to update catalogs mid-run.
     
    mikito-wp and Favo-Yang like this.
  13. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    493
    Thanks for implementing this features! I have some questions about this:
    1. When the remote catalog is updated, will GetDownloadSizeAsync() and DownloadDependenciesAsync() perform to only changed assetbundles properly?
    2. What happen if already loaded/used assetbundles are changed in remote catalog at runtime?
     
  14. yinyuewei

    yinyuewei

    Joined:
    Aug 16, 2018
    Posts:
    2
    how to use it? i used this code:
    var check = Addressables.CheckForCatalogUpdates(false);
    yield return check;
    Debug.Log(check.Result);

    but the Result has always zero-count item
     
    Last edited: Dec 4, 2019
  15. LudwigVRtualX

    LudwigVRtualX

    Joined:
    Oct 15, 2018
    Posts:
    8
    I would also appreciate a code example for this.
    EDIT: It might always be an empty list because the catalog that is used in the unity editor play mode always gets updated when building a new remote catalog.
     
    Last edited: Dec 5, 2019
  16. DrunkenMastah

    DrunkenMastah

    Joined:
    Sep 26, 2017
    Posts:
    28
    @unity_bill Please provide an example of this API. "CheckForCatalogUpdates"
    In general it is a good idea to just assume that everyone using any API will need an example to work with.
    Ps: On a Side note 1.5.0 of addressables documentation still mentions "Static Content" which is nowhere to be seen in the AddressableAssetSettings since the renaming of that field to "Can be changed / Cannot be Changed". Please update as it is causing confusion.
     
    faolad and phobos2077 like this.
  17. Atlantiss

    Atlantiss

    Joined:
    Aug 5, 2018
    Posts:
    14
    Any workaround to reinitialize addressables during runtime?
     
    faolad likes this.
  18. faolad

    faolad

    Joined:
    Jan 27, 2013
    Posts:
    98
    I will also like an example of how this works
     
  19. DrunkenMastah

    DrunkenMastah

    Joined:
    Sep 26, 2017
    Posts:
    28
    Bump. @unity_bill Please respond. Still stuck on this. Would appreciate any help.
     
    TigerHix and faolad like this.
  20. duartedd

    duartedd

    Joined:
    Aug 1, 2017
    Posts:
    65
    okay just trying to understand those 2 calls - checkfor catalogupdates and updatecatalog---


    Addressables.InitializeAsync().Completed += objects =>
    {
    Addressables.CheckForCatalogUpdates().Completed += updates =>
    Load(LabelsToDownload);
    };

    here is something that i have - What i am trying to do is to check for updates and then update if there is an update after the checkforcatalogupdates is checked it loadsassetsasyncs the addressables

    the good - all of it is working but havent tested out after i update existing build - but it checks for catalog updates but does it actually update the catalog?

    like am i supposed to initializeasync - > CheckForCatalogUpdates -> loadassetasync

    or
    initializeasync -> checkforcatalogupdates> if something true??? catalogupdate() -> loadassetasync ?

    or do i initializeasync -> catalogupdate() (it will automatically check and download the catalog???) -> -> loadassetasync

    this catalog the method is referring to is that the bundles or something else - where would they be located and how is that updated?

    for instance right now i have 7 asset packs which become .bundle s ( nothing else) - i put those in the remote server and voila they download but what about the bin file - how does build get a hold of the bin to say i need to update the assets ??? does checkcatalogupdates check to see if that bin file exists in the 'remote path' path or something?

    thanks for reading while I rant in wonder.
     
    faolad likes this.
  21. duartedd

    duartedd

    Joined:
    Aug 1, 2017
    Posts:
    65
    okay its working no issues

    step 1: check build remote content update - set the build and load path - i set to them to my remote paths

    build normal like its your first

    then make a change to an asset

    update existing build -selected the addressable content bin file

    i just uploaded all the files to the web serveer and change worked
    Addressables.InitializeAsync().Completed += objects =>
    {
    Addressables.CheckForCatalogUpdates().Completed += checkforupdates =>
    {
    if ( checkforupdates.Result.Count > 0)
    Addressables.UpdateCatalogs().Completed += updates => Load(LabelsToDownload);
    else
    Load(LabelsToDownload);
    };
    };

    note i used the default timestamp method cause that works for me and trying to keep things simple
     
  22. duartedd

    duartedd

    Joined:
    Aug 1, 2017
    Posts:
    65
    one more thing i am going to do is try to actually do the custom version instead of timestamp method instead see where that goes ...reason being is i wanted a way to get the old build to check if a new build needs to be fully downloaded - i think with a good numbering scheme i can program it in such a way to do this for me - for instance if the 1.02 and 1.03 are just patches and then from 1.03 to 2.00 would direct the player to download a new build from website or w.e

    I was going to just add a text file and read the build version from the asset but this gets around me having to download the assetpack and such first...will let you know what i get back and the code if i get it working!
     
    stevenchristian20 likes this.
  23. duartedd

    duartedd

    Joined:
    Aug 1, 2017
    Posts:
    65
    k so nope i misunderstood it and how it works i guess or should work ???? the version creates the name of the file with the name instead of the timestamp and when i update content it doesn't actually change the name of the file even no matter how many updates - stays 1.01 even though i change the override in the settings to 1.02 and stuff so that only gets used upon the first build creation i guess. Not sure if thats a bug or if that is just how they made it ... or maybe unity just hasnt implemented it fully yet
     
    stevenchristian20 likes this.
  24. duartedd

    duartedd

    Joined:
    Aug 1, 2017
    Posts:
    65
    FYI updated to 1.6.2 just to see if its something they worked on since 1.5 ( which was what i was on ) ...same thing - and my build doesnt read the new content build if i change it to 2.0 just in case that was their plan for that

    New thought though
    if i just delete the catalog files from the remote path and it cant find them i can prompt /redirect the player to download the new build
     
  25. virendra_bhoriwal

    virendra_bhoriwal

    Joined:
    Oct 25, 2018
    Posts:
    14
    @duartedd
    is this really working ? as I am also going through the same situation regarding how to get updates remotely. Could you please guide me....
     
    faolad likes this.
  26. faolad

    faolad

    Joined:
    Jan 27, 2013
    Posts:
    98
    Do you have "Disable Catalog Update on Startup" enable, in AddressableAssetSettings/Catalog?
     
  27. duartedd

    duartedd

    Joined:
    Aug 1, 2017
    Posts:
    65
    that is unchecked - i would assume if that is checked then it wont check the for updates and therefore will not update my assets regardless if there are changes...the issue was and is that when buiilding it grabs that timestamp (or player version override) file and it will use that name to check for updates looking for updates - it continues to use THAT name regardless of what other name you put in player version override - it will NOT create a new timestamp it will use the existing one (of course this is for use existing build) - for new builds it will create a new one and the old will be made obselete. Anyways pretty sure this is how it works from my testing.

    hope this helps!
     
    Voxel-Busters and faolad like this.
unityunity