Search Unity

Loading asset bundles directly from Streaming Assets

Discussion in 'Asset Bundles' started by liortal, Apr 3, 2017.

  1. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    *I realize this is a beta forum, but since it is related to asset bundles, i figured i'd post my question here. If not, please move to the appropriate forum, and let me know which forum i should post to in the future..

    I'd like to know if it's possible to load asset bundles directly from Streaming Assets, on all platforms ?
    I recall seeing an improvement some time ago (can't find it now) that support for this was added. But i may be wrong on that.

    So, is this supported right now? what is the proper way of loading asset bundles from streaming assets at the moment?
     
  2. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461

    You can, you just have to use WWW or WebRequest to do it..
     
  3. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    332
    This is fixed in 2017.1b2, I want to say it was fixed in earlier versions, but still trying to track down the PR to get more exact details. Will get back to you on this.
     
    Last edited: Apr 26, 2017
  4. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    332
    So digging a bit more into this one and found the fix. It was first fixed in 5.4.0f2, then backported to 5.3.6p3.
     
  5. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    @Ryanc_unity is this the fix where AssetBundle.LoadFromFile works with streaming assets on Android? i believe i tested this and it didn't work.
     
  6. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    332
    yes, here's are specific notes for those versions and the respective lines pertaining to this:

    https://unity3d.com/unity/qa/patch-releases/5.3.6p3
    (763293) - AssetBundles: Fixed AssetBundle.LoadFromFile usage with Application.streamingAssetsPath on Android.

    https://unity3d.com/unity/whats-new/unity-5.4.0
    [763293] Asset Bundles: Fixed AssetBundle.LoadFromFile usage with Application.streamingAssetsPath on Android.
     
  7. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    @Ryanc_unity we just tested this (Unity 5.5.3p1) and it doesn't seem to work.

    We have our own "asset bundle manager" object that loads Asset bundles from StreamingAssets (using AssetBundle.LoadFromFileAsync). We are now directly attempting to load from Application.streamingAssetsPath but it keeps returning null and the bundles cannot be loaded.

    Is there a chance that this is a regression, or are we doing something wrong ?

    Here's the code that essentially loads the bundles:
    Code (CSharp):
    1. private IEnumerator LoadAssetBundleFromStreamingAssetsCoroutine(string bundleName, string path, Action<AssetBundle> handler)
    2. {
    3.     // Loading asset bundle
    4.     var req = AssetBundle.LoadFromFileAsync(path);
    5.     yield return req;
    6.  
    7.     Assert.IsNotNull(req.assetBundle, "AssetBundleLoader : asset bundle wans't loaded from streaming assets");
    8.     Assert.IsNotNull(handler, "No callback handler");
    9.  
    10.     if (req.assetBundle == null)
    11.     {
    12.         handler(null);
    13.         yield break;
    14.     }
    15.  
    16.     handler(req.assetBundle);
    17. }
    NOTE: we're not keeping our files directly under streaming assets, they are stored under a few subfolders (not sure that matters).
     
  8. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    Never mind, ignore my previous message. it works fine.