Search Unity

UnityWebRequest.GetAssetBundle from StreamingAssets?

Discussion in 'Android' started by ShaneLillieGlu, Sep 12, 2016.

  1. ShaneLillieGlu

    ShaneLillieGlu

    Joined:
    Sep 2, 2015
    Posts:
    8
    We've been using WWW.LoadFromCacheOrDownload to copy asset bundles from StreamingAssets to the cache (for faster loading), but after attempting to switch to using UnityWebRequest.GetAssetBundle, we're now getting the following error:

    A URL Connection to a Java ARchive (JAR) file or an entry in a JAR file is not supported

    (the URL is jar:file:///data/app/). Is this use case something that will be supported in future releases, or perhaps is there a more appropriate way to go about getting bundles from StreamingAssets cached with UnityWebRequest? We're currently on 5.4.0p3. We would use AssetBundle.LoadFromFileAsync to load the file directly, but it takes significantly longer than loading a cached asset bundle, so being able to maintain this usage after WWW is deprecated would be very good for us.
     
  2. Zenix

    Zenix

    Joined:
    Nov 9, 2009
    Posts:
    213
    Bump... Did you ever find a solution to this?
    It works in the editor but on iOS I get "Received no data in response".
     
  3. Zenix

    Zenix

    Joined:
    Nov 9, 2009
    Posts:
    213
    Bump... still broken in 5.5
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    The support for this will come out soon in 2017.1.
    I'll probably backport this to older releases too.
     
  5. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,051
    I understand that this support it's not only for Asset Bundles isn't it? We need it for any file loaded with UnityWebRequest. There are other cases like xml, json, textures, videos...
     
  6. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    Yes, even though it is not recommended.
    For loading asset bundles from streaming assets you should use AssetBundle.LoadFromFileAsync().
    While on Android it's recommended to not use streaming assets for performance reasons. You are in fact reading from apk, which is a zip file.
     
  7. ObvSoft

    ObvSoft

    Joined:
    Mar 4, 2017
    Posts:
    7
    Hi! I'm currently working on AssetBundles and I also encounter this kind of problem.

    When you say :
    What do we should use instead ?
    For example, I have some textures variants that I want to load depending on screen resolution of the running device and I have no online server to host my AssetBundles what are my options ?
     
  8. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    AssetBundle.LoadFromFileAsync() can load abs from streaming assets and it is the recommended way to do this.
     
  9. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,051
    Yes but building an asset bundle implies more steps on workflow than simply putting files in streaming assets folder. Everytime you change something you need to build it for each platform you target. You also need to exclude in resources folder the asset bundles of the platforms that are not the currently one. Also the code to load the assets inside of it is not the same. It's not a trivial change.

    If you want people to start using asset bundles instead of streaming assets you should optimize and automatize this process.
     
  10. ObvSoft

    ObvSoft

    Joined:
    Mar 4, 2017
    Posts:
    7
    Thank you Aurimas-Cernius for the answer. If I understand correctly, in my case, I cannot avoid to use streaming assets, and I will have to deal with performance when I use AssetBundle.LoadFromFileAsync() on Android devices.

    To be sure to understand how AssetBundles works, am I right when I say :

    Another way to do handle this, is to have a web server where AssetBundles are stored and have the game calling UnityWeRequest functions to connect and download the bundles. I wonder if it means that the player should always be online when he/she play the game ?

    When I read these pages :
    https://docs.unity3d.com/Manual/AssetBundles-Patching.html
    https://docs.unity3d.com/Manual/AssetBundles-Native.html
    https://unity3d.com/learn/tutorials/topics/scripting/assetbundles-and-assetbundle-manager
    https://unity3d.com/learn/tutorials/temas/best-practices/assetbundle-usage-patterns#Distribution

    I suppose that AssetBundles will be downloaded the very first time the player launch the game and they will be cached. So the next time the player don't need to be online to play because asset bundles are presents in cache, right ?
     
    Last edited: Jun 7, 2017
  11. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    That's how AssetBundles are designed to be used: you download a bundle, cache it and use to from that on until you update your game and a newer version of asset bundle has to be used (or your game somehow finds out that the newer version of asset bundle is available online).
    You can ship asset bundle with your game too, but they were designed with download from internet in mind.
    Note: make sure you use our APIs properly for asset bundle to be cached, otherwise you will have to pay the download/decompression price all the time.
     
  12. ObvSoft

    ObvSoft

    Joined:
    Mar 4, 2017
    Posts:
    7
    Thank you very much for your time.
    It's really clear !
     
  13. adamt

    adamt

    Joined:
    Apr 1, 2014
    Posts:
    116
    I think I'm running into a similar issue here. I tried using AssetBundle.LoadFromFileAsync but that doesn't actually cache the file (I check Caching.IsVersionCached immediately after loading the bundle and it always comes back false), so when I next run UnityWebRequest.GetAssetBundle on any bundle that I'd previously loaded from StreamingAssets, it says it's not cached and re-downloads. Kind of the worst of both worlds (incurring the cost of bundling my assets with my binary and re-downloading them needlessly).

    I've fixed this on iOS by loading the AssetBundles from StreamingAssets using UnityWebRequest.GetAssetBundle, pointing at Application.streamingAssetsPath (with the file:// protocol). This caches the AssetBundles. However, UnityWebRequest doesn't like that path on Android.

    Is there a way to use AssetBundle.LoadFromFileAsync to cache the AssetBundles it loads, or is there another method I can use to properly load and cache AssetBundles stored in StreamingAssets on both Android and iOS?

    I'm using Unity 5.5, for reference.
     
  14. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    On Android Application.streamingAssetsPath already includes that ja:file:// protocol, all you need to append the file name to it and it can be loaded using UnityWebRequest.
     
  15. adamt

    adamt

    Joined:
    Apr 1, 2014
    Posts:
    116
    On Unity 5.5.3p3, that results in an exception, something to the effect of "Unknown" or "Invalid Protocol."
     
  16. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    Oh, right, reading streaming assets using UnityWebRequest was added in 2017.1.
     
    Draag likes this.
  17. adamt

    adamt

    Joined:
    Apr 1, 2014
    Posts:
    116
    Good to know. We're hoping we can upgrade to 2017.1 but the upgrade process is always a rocky one. Thanks for the follow-up!
     
  18. ferretnt

    ferretnt

    Joined:
    Apr 10, 2012
    Posts:
    412
    We have never managed to get UnityWebRequest and a DownloadHandlerTexture to load files from StreamingAssets on Android, and don't understand why. This is with Unity 5.6.3f1, but we have tried many other 5.x versions. The same code has always worked fine with WWW, and runs on all platforms other than Android. Note for sanity, we have constructed the path string in two different ways, and checked that filePathPerDocs and filePathFromStreamingAssets are identical.

    Code (csharp):
    1.  
    2.         // Construct path as recommended in https://docs.unity3d.com/Manual/StreamingAssets.html
    3.         string filePathPerDocs = "jar:file://" + Application.dataPath + "!/assets/" + fileName;
    4.         Debug.Log("File Path per docs: " + filePathPerDocs);
    5.  
    6.         // Construct path as we always have for streaming assets.
    7. string filePathFromStreamingAssets = Application.streamingAssetsPath + "/" + fileName;
    8.         if (Application.platform != RuntimePlatform.Android)
    9.         {
    10.             filePathFromStreamingAssets = "file://" + filePathFromStreamingAssets;
    11.         }
    12.         Debug.Log("File path using streamingassets: " + filePathFromStreamingAssets);
    13.  
    14.         // Load it. This will fail, but will work if using a WWW.
    15. using (UnityWebRequest www = UnityWebRequest.GetTexture(filePathFromStreamingAssets))
    16.  
    On Android, both of these functions build a string of the form:

    jar:file:///data/app/com.mycompany.application-nlg8YQn72iHpXna6k-FeqQ==/base.apk!/assets/imageToLoad.png

    And fail with: "A URL Connection to a Java ARchive (JAR) file or an entry in a JAR file is not supported."

    Can somebody tell me what is wrong with this string (e.g. by typing the correct form of the above string)? We have tried all manner of permutations of file://, ///, etc.

    Interestingly, this thread implies that UnityWebRequest streamingassets support on Android was only added in 2017.1 (post #16)

    https://forum.unity.com/threads/unitywebrequest-getassetbundle-from-streamingassets.430689/

    Yet there are replies higher in this thread (e.g. #5) saying it works in 5.6.

    https://forum.unity.com/threads/uni...files-on-android-failure.441655/#post-3266082

    I see nothing in the 2017.1 release notes saying that android streamingassets support for UnityWebRequest was added in this version. Unity release notes tend to be, umm, opaque but it would be great to clarify.
     
  19. tomerpeledNG

    tomerpeledNG

    Joined:
    Jul 14, 2017
    Posts:
    81
    We tried to do the same.
    Ship the apk with embedded initial asset bundles so that the users won't need to download lots of asset bundles during the startup of the app and also to be able to patch those assets if needed.

    However we didn't succeed to work with the StreamingAssets.
    We encountered the following issues:
    1. Error joining threads: 22
    We tried to LoadFromCacheOrDownload from the Application.streamingAssetsPath by going over a list of assets to be load for the first time the app launch (so that later on those assets will be in the cache).
    For simplicity of the POC, we just did this in a for loop with yield return in it on the WWW object.

    But we got the "Error joining threads" error.

    We did something like this:

    var www = WWW.LoadFromCacheOrDownload(streamingAssetsFile, theHash);
    yield return www;
    if(!string.IsNullOrEmpty(www.error))
    {
    Debug.Log(www.error);
    yield return;
    }

    Any idea what can cause this?

    2. We tried to work with the same code on some popular emulator, such as KoPlayer and we got the following crash:

    What we are missing? :(

    E/CRASH: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 000000fc
    04-30 00:22:24.498 17380-17401/com.nogame.nogameqa E/CRASH: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    04-30 00:22:24.498 17380-17401/com.nogame.nogameqa E/CRASH: Build fingerprint: 'SAMSUNG/hlteatt/hlteuc:4.4.4/tt/eng.jenkins.20170104.161952:userdebug/test-keys'
    04-30 00:22:24.498 17380-17401/com.nogame.nogameqa E/CRASH: Revision: '0'
    04-30 00:22:24.498 17380-17401/com.nogame.nogameqa E/CRASH: pid: 17380, tid: 17401, name: UnityMain >>> com.nogame.nogameqa <<<
    04-30 00:22:24.498 17380-17401/com.nogame.nogameqa E/CRASH: r0 00000018 r1 95744dcc r2 b850a6e0 r3 b9623730
    04-30 00:22:24.498 17380-17401/com.nogame.nogameqa E/CRASH: r4 95744dcc r5 b80bfa90 r6 00000000 r7 00000000
    04-30 00:22:24.498 17380-17401/com.nogame.nogameqa E/CRASH: r8 00000000 r9 00000000 sl 00000000 fp 00000000
    04-30 00:22:24.498 17380-17401/com.nogame.nogameqa E/CRASH: ip b9623760 sp 95744da0 lr 1610d34c pc 1610d054 cpsr 00000000
    04-30 00:22:24.498 17380-17401/com.nogame.nogameqa E/CRASH: backtrace:
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: #00 pc 0010d054 /data/app-lib/com.nogame.nogameqa-1/libunity.so
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: #01 pc 0010d348 /data/app-lib/com.nogame.nogameqa-1/libunity.so
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: #02 pc 00909a2c /data/app-lib/com.nogame.nogameqa-1/libunity.so
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: #03 pc 002db184 /data/app-lib/com.nogame.nogameqa-1/libunity.so
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: #04 pc 002fbeec /data/app-lib/com.nogame.nogameqa-1/libunity.so
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: #05 pc 00524190 /data/app-lib/com.nogame.nogameqa-1/libunity.so
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: #06 pc 005275e8 /data/app-lib/com.nogame.nogameqa-1/libunity.so
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: #07 pc 17fffffc <unknown/absolute>
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: stack:
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d60 00000000
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d64 00000000
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d68 00000000
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d6c 00000000
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d70 8db207a0
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d74 95744d18
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d78 00000000
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d7c 00000000
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d80 00000000
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d84 00000000
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d88 00000000
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d8c 00000000
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d90 00000000
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d94 00000000
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d98 00000000
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d9c 00000000
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: #00 95744da0 00000018
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744da4 b80bfa90 [heap]
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744da8 00000000
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744dac 1610d34c /data/app-lib/com.nogame.nogameqa-1/libunity.so
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: #01 95744db0 00000000
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744db4 16226e50 /data/app-lib/com.nogame.nogameqa-1/libunity.so
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744db8 00000000
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744dbc 95744e4c
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744dc0 b8515cf0 [heap]
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744dc4 00000ac6
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744dc8 1a217580 [stack:17398]
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744dcc 00000000
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744dd0 00000000
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744dd4 00000000
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744dd8 00000000
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744ddc 00000000
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744de0 95744e08
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744de4 16a84c54 /data/app-lib/com.nogame.nogameqa-1/libunity.so
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744de8 95744e10
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744dec 95744e2d
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: ........ ........
    04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: #02 95744e70 b850aba0 [heap]
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744e74 b9623730 [heap]
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744e78 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744e7c 162db188 /data/app-lib/com.nogame.nogameqa-1/libunity.so
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: #03 95744e80 00e1b446
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744e84 1710fdc8
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744e88 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744e8c 162fbef0 /data/app-lib/com.nogame.nogameqa-1/libunity.so
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: #04 95744e90 1a217580 [stack:17398]
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744e94 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744e98 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744e9c 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744ea0 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744ea4 000000c8
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744ea8 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744eac 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744eb0 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744eb4 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744eb8 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744ebc 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744ec0 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744ec4 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744ec8 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744ecc 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: ........ ........
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: #05 95744ee0 95953350 [anon:libc_malloc]
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744ee4 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744ee8 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744eec 165275ec /data/app-lib/com.nogame.nogameqa-1/libunity.so
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: #06 95744ef0 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744ef4 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744ef8 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744efc 18000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: #07 95744f00 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f04 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f08 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f0c 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f10 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f14 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f18 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f1c 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f20 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f24 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f28 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f2c 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f30 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f34 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f38 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f3c 00000000
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: memory near r1:
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744dac 1610d34c 00000000 16226e50 00000000 L.......Pn".....
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744dbc 95744e4c b8515cf0 00000ac6 1a217580 LNt..\Q......u!.
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744dcc 00000000 00000000 00000000 00000000 ................
    04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744ddc 00000000 95744e08 16a84c54 95744e10 .....Nt.TL...Nt.
     
    Last edited: Apr 29, 2018
  20. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    Which version is that on?
     
  21. tomerpeledNG

    tomerpeledNG

    Joined:
    Jul 14, 2017
    Posts:
    81
    2017.4.1f1
     
  22. tomerpeledNG

    tomerpeledNG

    Joined:
    Jul 14, 2017
    Posts:
    81
    We succeed to solve items 1 + 2 from what I wrote in my question above.

    For solving item 2 we just make sure we call DownloadHandlerAssetBundle.GetContent(webRequest) before disposing the UnityWebRequest object, even if we just wanted to download without getting the content. Seems like trigger the call to the GetContent solves the issue.

    Another issue that we are encountering now for some of our resources:
    - We ship several of our resources under the StreamingAssets folder
    - On the first startup of the app we load those resources to the cache - using the UnityWebRequest.
    - Later on we might load those assets again from the cache - using WWW.LoadFromCacheOrDownload. However for some of the resources we get this error "Received no data in response".
    Notice that we've added Caching.IsVersionCached to the logs and those resources are indeed in the cache, but for some of them calling WWW.LoadFromCacheOrDownload response with the mentioned error.
    - Also notice that if we do another retry to call WWW.LoadFromCacheOrDownload, it will go to download the resource from the provided url...

    Something that can be done to solve it? In what circumstances we might get the error: "Received no data in response"?
     
  23. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    Can you show an example code how you load those bundles?
     
  24. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    Hi, we're about to embark on something similar.
    But to clarify - we are putting our assetbundles into streaming assets, we're uploading the apk to google
    we wish to use LZMA to get around the OTA limit but we want to decompress to LZ4 into the cache when we first load the assetbundle post-install as we don't want to download assetbundles separately from other servers.

    We're using 5.6.5p4 - this should work ok?

    thnx
     
  25. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    Ok, works fine on iOS but doesn't work on Android 5.6.5p4 ( UnityWebRequest.GetAssetBundle )

    We get Unsupported Protocol as the error for Android.

    Do you know if the fix ever got back ported?

    thnx
     
  26. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    UnityWebRequest supports reading streaming assets on Android since 2017.1
     
    KB73 likes this.
  27. mrm83

    mrm83

    Joined:
    Nov 29, 2014
    Posts:
    345
    Just switched to UnityWebRequest.GetAssetBundle from DownloadorCache and it is not working for streamingAsset.
    Unity 2017.4

    The error is :
    InvalidOperationException: Cannot connect to destination host
    UnityWebRequest.GetAssetBundle works with streamingAsset if it is already cached, but it doesn't work if it is not cached.

    Is UnityWebRequest.GetAssetBundle suppose to work with streamAsset if it is not cached?
     
  28. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    Yes. Based on error the URL you pass to UWR is not correct (i.e. is invalid).
     
  29. mrm83

    mrm83

    Joined:
    Nov 29, 2014
    Posts:
    345
    The same url is used after caching and it works.

    Same url, before cached gives that error.
    Same url, after cached no error.

    The URL was also constructed by using the following:
    Application.streamingAssetsPath + bundlename
    bundlename is the exact filename of the bundle which exists inside the streamingasset folder
     
  30. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    Expected. Bundle is loaded from cache, so UWR doesn't care if URL points to an existing bundle.

    Print the actual string you pass to UWR. Such addition is also fragile (Path.Combine is recommended) and will not work on most platforms, since it is a file system path, not URI.
     
  31. mrm83

    mrm83

    Joined:
    Nov 29, 2014
    Posts:
    345
    Same error even with Combine.
    bundleUrl = System.IO.Path.Combine (Application.streamingAssetsPath, bundles.name);
    printed url is "/Users/Dev/Proj/Assets/StreamingAssets/sprites"

    Ok, i build the proj onto device and it works. The problem seems to be with the editor?

    Final Update:
    OK, so the path returned by Application.streamingAssetsPath is INVALID for editor!
    I manually appended "file:///" infront of the combined path and it works fine now.

    Is this a bug?
     
    Last edited: Nov 8, 2018
  32. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    No, it's not. You have to pass URI to UnityWebRequest, not file system path. So yes, you have to prepend file:// scheme.
    Note, that this is not true for some platforms, specifically Android and WebGL.
     
  33. daniFMdev

    daniFMdev

    Joined:
    Jun 21, 2017
    Posts:
    7
    I've just encountered this issue. However, prepending with "file:///" does not solve the issue for me. In my project, this is just not working on my Mac, but it does work in Windows (even without "file:///").

    Should I use a different header in Mac for the URI?
     
  34. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    Do not prepend "file:///".
    Instead create a System.Uri instance passing the file path to it's constructor, then give that Uri instance to UnityWebRequest.

    The reason why it fails is because on Mac and other UNIX-like operating systems absolute paths start with slash and URI syntax actually requires that, so the syntax is file:// (two slashes) plus the absolute path. Hence it does not work due to too many slashes. On Windows the proper URI looks like: file:///C:/dir/subdir/file (motice the three slashes here). BTW, Unity does accept URI with only two slashes on Windows as a relaxed form, but we do recommend using System.Uri instead, since that one allows to write platform independent code.