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?
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.
@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.
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.
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
@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
public static IAsyncOperation<IResourceLocator> Initialize()
{
if (s_initializationOperation != null)
return s_initializationOperation;
...
}
To
public static IAsyncOperation<IResourceLocator> Initialize(bool forceRefresh = false)
{
if (s_initializationOperation != null && !forceRefresh)
return s_initializationOperation;
...
}
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.
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.
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.
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.
@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.
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.
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.
@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.
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?