Can't load the same AssetBundle twice

I use UnityWebRequest wwwTexture = UnityWebRequestAssetBundle.GetAssetBundle(bundlePath) to download AssetBundles which contain textures. I preload all the textures at the start of the game, so the user won’t need to wait for downloads to complete once they start. I add these textures to an array, which I load each time the player reaches a new level. Sometimes the same texture is used for multiple levels, but the level has other properties that make it different.
When I try and load the same level more than once using AssetBundle myLoadedAssetBundle = DownloadHandlerAssetBundle.GetContent(wwwTexture); I get the following error:
The AssetBundle ‘http://MyGame/level3’ can’t be loaded because another AssetBundle with the same files is already loaded.
The only time I can know the name of the texture is after calling the GetContent function, and this throws the error. The wwwTexture doesn’t seem to have a property that would allow me to know if I already loaded the asset. My server encodes the names of the levels differently even if they have the same texture.

Any ideas would be appreciated.

When I implemented a similar system (quite some time ago now), we kept our own record of what was downloaded / loaded at a given time.

From memory, rather than loading AssetBundles directly, we did everything through a manager class. It kept a dictionary associating URLs with downloaded bundles. When we needed to access a bundle it would check that dictionary. If the content associated with the URL was downloaded it’d raise the appropriate event immediately, otherwise it’d add the download to a queue and raise the event when the content was available.

What if you download different AssetBundles with the overlapping content, do you run into the same issue? By the nature of the content we were using this wouldn’t have been an issue for us. It’s definitely solvable, but will complicate things a bit.

Unfortunately I have little control over the server side, so I am hoping to find a solution that would work entirely client side.
The bug is caused since all urls are unique, but sometimes the AssetBundles are the same.
I essentially need a way to know if I already downloaded the wwwTexture or to somehow get the name of the AssetBundle before calling GetContent. The wwwTexture downloads without a problem, but as soon as I try and turn it into an AssetBundle I get the error.

These are the solutions I tried:
a) I added a try catch around DownloadHandlerAssetBundle.GetContent(wwwTexture), but the error was still thrown by the Unity static function GetContent. Otherwise I would have just reloaded the data from the cache if I tried loading a texture that remained null.
b) I tried saving the wwwTexture, but as soon as I leave the UnityWebRequest loop it is deleted.
c) I tried checking the hash of the wwwTexture, but it is different even if the AssetBundle is the same.

Any other ideas?

May I ask why? Also, do you have control over what gets put on the server, ie: how the AssetBundles are created? Ideally this would be designed as one contiguous pipeline, rather than having different people or departments hacking away at stuff in isolation…

My first thought is to deal with the problem properly at the root - avoid content overlap in the first place. Failing that, running a checksum/has over AssetBundles when they arrive but before getting their content could help, if “AssetBundles are the same” means that they are copies of the same file.

No, I essentially have no control over the server. I just need a way to know if the AssetBundle is already in memory, and from there I can deal with the issue myself.

You should read this documentation: Unity - Scripting API: Networking.UnityWebRequestAssetBundle.GetAssetBundle

Asset bundles are identified by filename and version.

The only way to get the filename of the Asset is to call GetContent, but this function crashes the application if the Asset was already loaded.

You can’t load the same Asset Bundle twice. You can use this to get all loaded bundles: