Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

WWW.LoadFromCacheOrDownload(string url, Hash128 hash) strange behaviour

Discussion in 'Scripting' started by imurashka, Jun 26, 2015.

  1. imurashka

    imurashka

    Joined:
    Aug 5, 2012
    Posts:
    20
    Hi!

    I have problem with method WWW.LoadFromCacheOrDownload(string url, Hash128 hash). For example this code:
    Code (CSharp):
    1. Hash128 hash = Hash128.Parse("any_string");
    2. Debug.Log(Caching.IsVersionCached(localURL, hash));//False
    3. WWW www = WWW.LoadFromCacheOrDownload(localURL, hash);
    4. yield return www;
    5. Debug.Log(www.error);//Null
    6. Debug.Log(Caching.IsVersionCached(localURL, hash));//True
    has strange behaviour. As you can see I wrote wrong Hash128 for the existing bundle. Before downloading this bundle the method Caching.IsVersionCached(localURL, hash) returns False (that is OK). But after downloading (right bundle with wrong hash) this method returns True and no errors in www.error.

    Could you help me please?
     
  2. ANTARES_XXI

    ANTARES_XXI

    Joined:
    Dec 23, 2014
    Posts:
    141
    Well, it's normal behaviour:)
    Caching.IsVersionCached and WWW.LoadFromCacheOrDownload works with version parameter, so in your case:
    1) You calculate some hash value (f. e. it's 123) and use it as version parameter
    2) You check IsVersionCached for localURL and version 123, but there's no cached localURL with version 123 -> you get False
    3) You LoadFromCacheOrDownload localURL with version 123, but there's no cached localURL with version 123 -> it downloads localURL and caches with version 123
    4) Finally you check IsVersionCached for localURL and version 123 again and that's it -> no www.error and True result, cause localURL with version 123 already exists in the cache
     
  3. imurashka

    imurashka

    Joined:
    Aug 5, 2012
    Posts:
    20
    Ty for your reply!