Search Issue Tracker
By Design
By Design in 2023.1.X
Votes
0
Found in
2023.1.0a1
Issue ID
UUM-2279
Regression
No
Caching.GetCachedVersions returns zero when AssetBundle is downloaded
Reproduction steps:
1. Open the user's attached "My project.zip" project
2. Open the "SampleScene" Scene
3. Enter the Play mode
4. Press the "Download" button
5. Press the "Check If Downloaded" button
6. Observe the messages displayed in the Scene
Expected result: Caching.GetCachedVersions returns all cached versions of the given AssetBundle
Actual result: Caching.GetCachedVersions returns zero
Reproducible with: 2020.3.35f1, 2021.3.3f1, 2022.1.3f1, 2022.2.0a15
Couldn't test with: 2019.4.39f1 ("The AssetBundle can't be loaded because it was not built with the right version or build target." error)
Note: If buttons aren't visible in the Scene, set the Aspect Ratio to "800x480 Portrait"
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Out-of-bounds memory access with multiple CanvasRenderers under a Canvas when using Mesh API
- Inspector tries to access file after it was deleted when the file was locked in Inspector window
- Changing Transform values in Search window Inspector loses focus while dragging and stopping mouse without releasing dragging action
- Saving changes on the dirty VFX Graph during the Play mode throws "The referenced script (Unknown) on this Behaviour is missing!" warnings
- VFX Graph Debug Info overlaps the "Initialize" block debug info by default
Resolution Note:
We've examined the project and some code changes are needed to enable the cache. With a few lines of code changes the example is working (tested with 2021.3 Windows Standalone)
With those code changes a cache file was successfully saved to a path like:
%USERPROFILE%\AppData\LocalLow\Unity\DefaultCompany_My project\prefabs\bundle\00000000000000000000000001000000
And a console message "Caching.GetCachedVersions(prefabs/bundle) = 1" was observed.
The code change is:
IEnumerator RequestAssetBundleCoroutine(string assetBundleName)
{
string url = "https://www.the3rdsequence.com/_/test/" + assetBundleName;
CachedAssetBundle cacheInfo = new CachedAssetBundle();
cacheInfo.name = assetBundleName;
cacheInfo.hash = new Hash128(0, 0, 0, 1);
request = UnityWebRequestAssetBundle.GetAssetBundle(url, cacheInfo, 0);
1) Because the assetbundle name is a relative path it must be provided in the CachedAssetBundle.name structure, otherwise by default the last name in the URL is used. ("bundle" versus "prefabs/bundle")
2) The cache is only used when a version integer or hash is provided. The version is mandatory for caching because otherwise it would be impossible in future to replace an assetbundles already in the cache when a new build is released. This is mentioned in the reference for UnityWebRequestAssetBundle.GetAssetBundle.
Resolution Note (2023.1.X):
We've examined the project and some code changes are needed to enable the cache. With a few lines of code changes the example is working (tested with 2021.3 Windows Standalone)
With those code changes a cache file was successfully saved to a path like:
%USERPROFILE%\AppData\LocalLow\Unity\DefaultCompany_My project\prefabs\bundle\00000000000000000000000001000000
And a console message "Caching.GetCachedVersions(prefabs/bundle) = 1" was observed.
The code change is:
IEnumerator RequestAssetBundleCoroutine(string assetBundleName)
{
string url = "https://www.the3rdsequence.com/_/test/" + assetBundleName;
CachedAssetBundle cacheInfo = new CachedAssetBundle();
cacheInfo.name = assetBundleName;
cacheInfo.hash = new Hash128(0, 0, 0, 1);
request = UnityWebRequestAssetBundle.GetAssetBundle(url, cacheInfo, 0);
1) Because the assetbundle name is a relative path it must be provided in the CachedAssetBundle.name structure, otherwise by default the last name in the URL is used. ("bundle" versus "prefabs/bundle")
2) The cache is only used when a version integer or hash is provided. The version is mandatory for caching because otherwise it would be impossible in future to replace an assetbundles already in the cache when a new build is released. This is mentioned in the reference for UnityWebRequestAssetBundle.GetAssetBundle.