Update addressable assets at runtime with new assets from remote CDN

Hello. Many of the addressable samples and demos I’ve seen show how to update addressable assets with content from a remote CDN. However, in this case, the game must be restarted to get the updated assets.

Is it possible to update addressable assets at runtime (i.e., no restart)? If so, how?

I have tried a few different approaches that use
Addressables.CheckForCatalogUpdates and Addressables.UpdateCatalogs
And then I call something like
newTexture.LoadAssetAsync where newTexture is an AssetReferenceTexture. Then, I change the mainTexture on the material for my mesh.

I’ve also tried an approach that first calls
Addressables.LoadResourceLocationsAsync to get a list of IResourceLocations. Then I iterate over each location, and call
Addressables.LoadAssetAsync Then, I change the mainTexture on the material for my mesh.

Neither approach is working for me.

It’s working mostly for me.

So, I build my app without any ABs (if you also, make sure you have cleaned your addressable ABs before, as they elsewise would be copied into your applications data folder), then build the ABs and upload ABs and catalogue to the CDN.

Then I call Addressables.UpdateCatalogs to get the latest catalogue from the CDN and call Addressables.LoadAssetAsync(textureIdentifier) and put that result into my texture. I’m not using AssetReference actually, but it works for me.

Only thing which is not working “correctly” is that the catalogue doesn’t seem to be cached .

2 Likes

Thanks, Pahe. This is great info.

I changed a few lines of code to line up with what you’re doing, and I still cannot update the texture (or material) at runtime. I’ll keep trying a few more variations in code. Or maybe something is wrong with my Addressables settings.

Question: When you say “textureIdentifier” above, do you mean a hard coded string that points to your texture (e.g., Assets/Textures/newTexture.png)? Or do you get the IResourceLocatorfrom the catalogs returned from Addressables.UpdateCatalogs?

textureIdentifier is the identifier of the addressables asset, you have defined in the inspector.

5839231--619627--identifier.png

1 Like

For anyone attempting to update assets at runtime using the Addressables system, I’ve figured out (with some help) how to do it with textures and materials. Here are the recommended steps:

  • Load mesh (Addressables or not), get access to material
  • newTexture.LoadAssetAsync - set this as mainTexture on material for mesh (newTexture is an AssetReferenceTexture).
  • Addressables.CheckForCatalogUpdates
  • If no updates, done. If updates, proceed
  • newTexture.ReleaseAsset - will give the mesh a pink texture, so ideally you’ve also hidden or disabled this mesh
  • Addressables.UpdateCatalogs
  • Get access to material again (listing this step in case reloading is required)
  • newTexture.LoadAssetAsync - set this as mainTexture on material for mesh

This process should work for reloading a texture via Addressables and swapping Renderer.sharedMaterial.mainTexture reference at runtime. It works with either AssetReferenceTexture.LoadAssetAsync or Addressables.LoadAssetAsync(“name”) workflows.

2 Likes