Search Unity

AssetBundle LoadFromFileAsync Problem

Discussion in 'Documentation' started by dengqingbin, Apr 26, 2016.

  1. dengqingbin

    dengqingbin

    Joined:
    Apr 26, 2016
    Posts:
    10
    Hi,guys
    My question is about loading assetbundle from the apk.

    In unity5.3 manual, there is one solution that could use lz4 compression assetbundle(http://docs.unity3d.com/Manual/AssetBundleCompression.html): Thus, use the following guidelines when using low-level loading API in your games: 1.Deploying asset bundles with your game as StreamingAssets - use BuildAssetBundleOptions.ChunkBasedCompression when building bundles and AssetBundle.LoadFromFileAsync to load it. This gives you data compression and the fastest possible loading performance with a memory overhead equal to read buffers.

    When I did tests on my android pad, the "AssetBundle.LoadFromFileAsync" interface can only load all three kind of compression assetbundle(the default lzma and lz4 and uncompressed) from the Application.persistentDataPath path which is really read from disk after assetbundle files were decompressed from the apk with my own code.However, the "AssetBundle.LoadFromFileAsync" interface did not work out when it comes to load assetbundle files from the apk directly.

    Did I miss something ? Or did I misunderstand the description ? It will be great help to me if someone can figure it out.Thanks.
     
  2. dengqingbin

    dengqingbin

    Joined:
    Apr 26, 2016
    Posts:
    10
    Done, should use Application.dataPath + "!assets" for the load directry when you want to load assetbundles with AssetBundle.LoadFromFile(Async)from the app directly on android.
     
  3. kpimpdaddy

    kpimpdaddy

    Joined:
    Jul 18, 2016
    Posts:
    1
    Thanks for the solution. I usually use streamingAssetsPath when I load assetbundles through WWW. However, as you mentioned above, local assetbundles in the application are no longer loaded by WWW but AssetBundle.LoadFromFile. Now I have a question. Can you tell me the reason why the path(dataPath+!"assets") works for LoadFromFile on Android?
     
  4. dengqingbin

    dengqingbin

    Joined:
    Apr 26, 2016
    Posts:
    10
  5. alexeyzakharov

    alexeyzakharov

    Joined:
    Jul 2, 2014
    Posts:
    507
    Internal filesystem didn't recognize "jar:file://" prefix before. But a valid path could be constructed from Application.dataPath (which is also used to construct Application.streamingAssetsPath). Basically, it could be (dataPath+"/assets") - there should be one character before "assets".
    This bug is fixed in 5.4.