Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Code example to load StreamingAssets

Discussion in 'Android' started by JasonOrtinskid, Mar 28, 2016.

  1. JasonOrtinskid

    JasonOrtinskid

    Joined:
    Jan 6, 2016
    Posts:
    22
    Hello.

    I am not able to access StreamingAssets for AssetBundle purpose for Android. Works fine in Editor but not in Android. Does anyone know how to do this? Here is what I did.
    string localbundlePath = Application.streamingAssetsPath+"/localbundle";
    Debug.LogError("gettinglocalBundle:"+localbundlePath);
    string url = new WWW(localbundlePath).url;
    Debug.LogError("gettingurl:"+localbundlePath);
    BundleLoaderB.localBundle = AssetBundle.LoadFromFile(url);

    The error is:
    Unable to open archive file: jar:file:///data/app/com.bob.game-1/base.apk!/assets/localbundle
     
    Last edited: Mar 30, 2016
  2. ratmat2002

    ratmat2002

    Joined:
    Jun 13, 2014
    Posts:
    35
  3. JasonOrtinskid

    JasonOrtinskid

    Joined:
    Jan 6, 2016
    Posts:
    22
    I thought Asset Bundles are a major feature for Unity. SMH.... I can't find any documentation that doesn't involve remote downloaded bundles.
     
  4. JasonOrtinskid

    JasonOrtinskid

    Joined:
    Jan 6, 2016
    Posts:
    22
    So far the only way it works is with WWW.LoadFromCacheOrDownload. But that's not good, I don't want to extract it, I just want to read from the bundle like Resources.Load(). I wonder if anyone has ever succeeded?!?
     
  5. ratmat2002

    ratmat2002

    Joined:
    Jun 13, 2014
    Posts:
    35
    From what I can tell, the answer is no. No one has been able to do it and Unity moderators won't answer the question.

    I have trued using WWW.LoadFromCacheOrDownload with local AssetBundles stored in the StreamingAssets folder and I get the same error (an yes I prepended the URL with file:// when trying).

    They have documentation here that is very hard to find but things don't work the way they say it should:

    http://docs.unity3d.com/Manual/AssetBundleCompression.html
     
  6. JasonOrtinskid

    JasonOrtinskid

    Joined:
    Jan 6, 2016
    Posts:
    22
    are u using ios or android? For me, www.loadfromcacheordownload works for android, loadfromfileasync works for mac and ios. but it would be better if loadfromfileasync works for android too because no need for decompression and taking up more than double the space of what the bundle already takes.
     
  7. ratmat2002

    ratmat2002

    Joined:
    Jun 13, 2014
    Posts:
    35
    I'm trying loadfromfileasync on iOS with Unity 5.3.4f1 but getting the "Unable to open archive file" error on iOS. It works on OSX. I haven't tried Android since I started using 5.3.4f1.

    Do you file paths include file:// before the file name when using loadfromfileasync or not? If you could include a snippet of your code including the loadfromfileasync call, that would be much appreciated.
     
  8. alexeyzakharov

    alexeyzakharov

    Unity Technologies

    Joined:
    Jul 2, 2014
    Posts:
    507