Search Issue Tracker

By Design

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"

  1. 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.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.