Addressables Version and Cache

Hi
I’m new to Addressables and am confused about some basics that I can’t get over.

First of all…
Version: I’m using Addressables version 1.8.5 because it’s the “Verified” version, but there are several newer versions and I’m wondering which is the newest stable version to use for my project.
Cache: I’m not sure if I understand “cache” correctly because it didn’t work as intended in my tests. I assume “cache” means files stored on disk (not just in memory) and preserved across multiple game sessions.

Brief description of what I’m trying to do in my game (for mobile):

  • I have items with data (text and image) and a 3D model. The items should all be available in the cloud.

  • My solution so far:
    → Addressables Build- and Load-Path on “cloud” (currently local)

  • When the game starts, the shop should load individual items (let’s say 5 out of 500 items) based on their rarity. I don’t want to load all items and list 5 in the shop, just load the 5 and only the item data (text and image) should be loaded.

  • My solution so far:
    → I made a ScriptableObject with a list of AssetReferences and load this SO at start.
    → I bundle the assets separately (Bundle Mode: Pack Separately).
    → Then I load randomly 5 Items from the list. (random index)
    → Item data contains text, image and AssetReference to 3d model.

  • If a player buys an item in the shop, this item is added to the inventory and the 3D model should be loaded.

  • My solution so far:
    → Load 3d model from AssetReference in item data.

  • In 2nd and 3rd, I want the loaded data to remain in the cache so that it doesn’t have to be reloaded when exiting and restarting the game.

  • What I tried so far:
    → Checked “Use Asset Bundle Cache” but this doesn’t seem to work.

  • I would like to remove the data in the “cache” independently at certain times. (For 2nd: When new items are generated in the shop. For 3rd: When the item is removed from the inventory.)

  • No solution needed so far because cache doesn’t work…

I have the following questions about the whole issue:

  • Which Addressables version is currently recommended?
  • Do I understand correctly that cache persists across game sessions and why doesn’t it work for me?
    I don’t see any files in the alleged cache path and the first loading takes longer with every restart.
    (And how can I debug this properly?)
  • To load individual items, it seems like there has to be a better solution. Is there a way I can access the Addressables catalog and get a List of the available Items? And if so, can I use labels to differ between different rarity?
  • If I have a remote path in which to build and load, it keeps building more and more “versions” of the builds, keeping the old ones. Do I have to delete them manually or are there interesting settings that I have overlooked? (like version control, rollback, delete automatically after version 5…)
  • How can i manage the cache manually? (or also automatically)
  • It’s up to you, but the recommended one is the “stable” one, keep in mind that this changes depending on your Unity version.

  • Yes and no. Cached assets doesn’t mean that they don’t need to be reloaded, those assets that don’t need to be re downloaded. You will still need to load them, but if no update is available for the asset then it will not be downloaded.

  • When you load a remote catalog, you get a list of all the locations. You could use that to load them all, but labels is a correct workaround too. What I do is have a ScriptableObject (like you do) that I manually load then I have the array of assets there that I can just load.

  • Those are so that old versions of your game still work, if you remove them then people that haven’t updated yet will not be able to load the assets. While developing you can delete them to make sure that only the last version is used. This of course can be avoided with forced updates, but that’s a configuration of the application.

  • What exactly you mean with manage? What are you trying to do with it?

Thank you for your Answers.

  • The unity version dependency is a nice touch that I wasn’t aware of. I found out that the newer ones have some nice features (like “GetDownloadStatus”, even though I don’t realy get it how it works because “TotalBytes” and “DownloadedBytes” are always 0 and “progress” is either 0 or 1)
  • Yes, thats exactly what I meant. The only thing that matters to me is that I don’t have to download the data again. But I somehow don’t get it how i can check if the items are cached. I wanted to get the cachePaths (“Caching.GetAllCachePaths”) but the listed path doesn’t exist. How can I debug this?
  • How can I access the catalog and its content? Because I don’t want to load all Items in one group but just some of them. Lets say we have the example below and want to load randomly 3 common, 2 rare and 1 epic item. How can i do this?
  • That makes sense.
  • I want to be able to delete the cached Assets I don’t need anymore to free up some local space. (Like items in the shop the player didn’t buy and disappear when the items refresh or when a player destroys the item in his inventory.)

Example:

  • Group 1 (Packed Separately)

  • Label: Common

  • Asset 1

  • Asset 2

  • Asset 3

  • Asset 4

  • Label: Rare

  • Asset 5

  • Asset 6

  • Asset 7

  • Label: Epic

  • Asset 8

  • Asset 9

If i’d have a dictionary of this (Dictionary<Rarity, List>) i could get the list of each rarity, get random index numbers and load the Assets.

  • It depends on how the download is going, but I’ve seen mine being updated correctly if the file is big enough.
  • For debug it, you can manually search for the files in the cache path which is either Caching.currentCacheForWriting.path or Application.persistentDataPath + "/com.unity.addressables/ can’t remember right now
  • You cannot access a catalog or group with a reference. You’ll have to do it when you are downloading your catalog with the url. If they are not remote, then use labels. Unfortunately I haven’t found of other way to do it. Note that depending on your group settings, you can just load an asset instead of the whole group. This will allow you to use the structure you provided above but just load the required assets instead of the whole group. Note, that load and download is not the same, the whole group will be downloaded, but not loaded into memory.
  1. You’ll need to manually delete them from the paths above, the hard part will be to be able to identify what file correspond to an asset.
  1. Even with bigger files it’s always 0 (DownloadedBytes, TotalBytes, Percent) until it’s loaded and Percent becomes 1… but this isn’t even bothering me that much if the rest would work…
  2. I checked out both path
    2.1 Application.persistentDataPath + “/com.unity.addressables/” gets created and i think it just contains the catalog (.has- and .json-files)
    2.2 Caching.currentCacheForWriting.path doesn’t get created but if i create it myself there is a “__info” file inside when i hit play in unity.
    Info File:

1678643993
1
0

  1. Well then i’ll use my workaround. Maybe something like that will be supportet in newer versions…
  2. I hope i’ll find a way to do this. But sadly i still struggle to even get some cache files…

So the Build, Load & Release part is working fine and also the memory management (analyzed with the “addressable event viewer”)

But I just can’t get it work to get some cache files…
My settings:

  • Top Level:

  • Build Remote Catalog is checked

  • Build Path: Local path on pc for testing

  • Load Path: Same path as Build path

  • Group:

  • Use Asset Bundle Cache is checked

Any other thing that is needed?

Feedback to 1st!

→ I was able to track the download with “handle.PercentComplete”. I think “GetDownloadStatus” is just not working by now…

PROGRESS! :sunglasses:

I tried different Addressables versions (I use the Unity Version 2021.3.10f1 LTS) and Addressables 1.20.5 brings two errors:
Library\PackageCache\com.unity.addressables@1.20.5\Runtime\AssetReference.cs(924,27): error CS0117: ‘AssetDatabase’ does not contain a definition for ‘SaveAssetIfDirty’
and
Library\PackageCache\com.unity.addressables@1.20.5\Runtime\AssetReference.cs(924,58): error CS0117: ‘AssetDatabase’ does not contain a definition for ‘GUIDFromAssetPath’

Both “SaveAssetIfDitry” and "GUIDFromAssetPath"should exist in 2021.3.

However i decided to go with the Addressables version 1.19.19 (becuase it came with 2021.3).

The only think still missing is saving assets localy so the game doesn’t need to download them every time the game starts and it also works offline after the first download.

It seems like the cache only works for downloaded assets. That might be why you don’t see them. I have an example on how I work around the system here: https://discussions.unity.com/t/892288 I have a couple of examples for catalogs and deleting cached assets

I had that error before, that happens when you use an old Unity version

It works! (i guess xD)

I think the problem was that i tested it with the build saved localy. I use my NAS now to test it and the cache files get created, can be loaded and released again (and releasing deletes the cache instantly).

To be 100% sure i have to make a few more tests but so far it looks as if i can use it as I need it.

Thank you Rotary-Heart for helping me out!