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

Failed to load asset bundle

Discussion in 'iOS and tvOS' started by danielsonchris, May 3, 2011.

  1. danielsonchris

    danielsonchris

    Joined:
    Feb 12, 2011
    Posts:
    43
    Thanks for any help in advance!
    I have a basic assetbundle project where I use my custom UnityEditor scripts to compile a simple Box and Texture2D into a single prefab assetbundle named "iphone-prefab-box.assetbundle".

    Everything compiles and runs fine within the Unity 3.3 environment:

    Code (csharp):
    1. private WWW www;
    2. IEnumerator Start () {
    3.     String strPath = "file://" + Application.dataPath + "/../assetbundles/iphone-prefab-box.assetbundle";
    4.     Debug.Log(strPath);    
    5.     www = new WWW(strPath);
    6.     yield return www;
    7.     AssetBundleRequest request = www.assetBundle.LoadAsync("Box", typeof(GameObject));
    8.     yield return request;
    9.     Instantiate(request.asset, new Vector3(3f, 0f, 0f), Quaternion.identity);
    10.     Instantiate(request.asset, new Vector3(0f, 0f, 0f), Quaternion.identity);
    11.     Instantiate(request.asset, new Vector3(-3f, 0f, 0f), Quaternion.identity);
    12. }
    When I cross-compile and run this in XCode on an iOS device I get the following error:

    I've included the "assetbundles" directory into my XCode project as well. I'm probably missing something simple here! Any ideas guys?

    $Screen shot 2011-05-03 at 8.04.15 AM.png
     
    Last edited: May 3, 2011
  2. tigershan

    tigershan

    Joined:
    Jul 29, 2010
    Posts:
    73
    same problem I have....
     
  3. danielsonchris

    danielsonchris

    Joined:
    Feb 12, 2011
    Posts:
    43
    Well I've gotten past the "Failed to load asset bundle" error now. I simply copied my prefab into the Data folder using the Terminal and that fixed everything up.
    cp my-prefab.assetbundle /Users/<user account>/Documents/projects/unity/MPLib/iOS/Data


    Now I'm getting a new error:

    -> applicationDidBecomeActive()
    The file can not be loaded because it was created for another build target that is not compatible with this platform.
    Please make sure to build asset bundles using the build target platform that it is used by.

    (Filename: /Applications/buildAgent/work/6bc5f79e0a4296d6/Projects/../Runtime/Serialize/SerializedFile.cpp Line: 210)

    The asset bundle 'file:///var/mobile/Applications/2A782E51-DD70-4F3B-970A-C030C84258E4/test1.app/Data/iphone-prefab-box.assetbundle' can't be loaded because it was not built with the right version or build target.

    (Filename: /Applications/buildAgent/work/6bc5f79e0a4296d6/Projects/../Runtime/Misc/AssetBundleUtility.cpp Line: 58)



    I'm going to try and rebuild the prefab now using my script after I change the Unity engine to use the iOS build. I'll report my results here when I'm finished.
     
  4. tigershan

    tigershan

    Joined:
    Jul 29, 2010
    Posts:
    73
    rather than manually copying the prefab, have you try to write it to cache? and read from it? using your current method see if it works?
     
  5. danielsonchris

    danielsonchris

    Joined:
    Feb 12, 2011
    Posts:
    43
    Fixed! Everything is working like a champ now. OK, here is what I did to fix that last error:

    Changed this line of my UnityEditory script:
    BuildPipeline.BuildAssetBundle(null, assets.ToArray(), path, BuildAssetBundleOptions.CollectDependencies);

    Changed to:
    BuildPipeline.BuildAssetBundle(null, assets.ToArray(), path, BuildAssetBundleOptions.CollectDependencies, BuildTarget.iPhone);

    Everything works great here now. The project runs without crashing and I can see my instantiated assets on the iOS (iPhone 4).
     
    Last edited: May 3, 2011
  6. danielsonchris

    danielsonchris

    Joined:
    Feb 12, 2011
    Posts:
    43
    I see the thread you are referring to now. http://forum.unity3d.com/threads/87805-Read-Write-Cache-IOS-Iphone-AssetBundle-Problem

    I'm going to take a guess that on your second click of the download asset button, the code is incorrectly detecting the cache. You're probably going to need to insert in more Debug.Log statements around your code including making sure that the file paths are 100% accurate. I would do a file system check and not rely on a download flag as well. Just my 2 cents.
     
  7. danielsonchris

    danielsonchris

    Joined:
    Feb 12, 2011
    Posts:
    43
    Wanted to clarify something here as well. You do not need to use the Terminal and copy your assets into the Data folder, etc. Instead, you would want to do the following.

    Drag your "assetbundles" or whatever the folder name is onto the root of your XCode project and then select as shown in the attached screenshot.

    $Screen shot 2011-05-03 at 10.53.56 AM.png

    This then will load perfectly using the following path code:

    Code (csharp):
    1. String strPath = "file://" + Application.dataPath + "/../assetbundles/iphone-prefab-box.assetbundle";
     
  8. Risine

    Risine

    Joined:
    Dec 10, 2009
    Posts:
    154
    Hi everyone,

    I'm just trying to include assets bundles in my ios app, just like in this example, but it does not work.

    It works in Unity editor, but when I add my bundle directory in the xcode as done there, ( the directory appears correctly at the root in the .app file with all asset bundle files inside ) and launch the game on my Iphone3G, it just does not work.

    Any idea?
     
  9. danielsonchris

    danielsonchris

    Joined:
    Feb 12, 2011
    Posts:
    43
    Error logs?
     
  10. Ntero

    Ntero

    Joined:
    Apr 29, 2010
    Posts:
    1,436
    You can automate much of the transfer process with a folder named Assets/StreamingAssets.

    In Editor it's located as Application.dataPath + "/StreamingAssets/" and on device it's located at Application.dataPath + "/Raw/".

    Unity automatically copies it as a build process into your XCode project and .app bundle.
     
  11. Risine

    Risine

    Joined:
    Dec 10, 2009
    Posts:
    154
    Great, i'll give it a try and let you know.

    Thanks all !!!
     
  12. Risine

    Risine

    Joined:
    Dec 10, 2009
    Posts:
    154
    Still does not work, but data are well placed in RAW .app folder.
    Maybe there's something wrong in my code.

    Here's what I do in the Start of my GameObject :
    WWW www = new WWW("file://" + Application.dataPath + "/Raw/" + name + ".asb");
    yield return www;

    // Load asset texture.
    Texture2D inter = www.assetBundle.Load(texture) as Texture2D;
    mat.SetTexture("_MainTex", inter);
    www.assetBundle.Unload(false);

    Any idea?
     
  13. danielsonchris

    danielsonchris

    Joined:
    Feb 12, 2011
    Posts:
    43
    Working through a resolution for this issue as well. Risine, are you using the latest Unity 3.4.2 release as well? I just updated to this version and noticed this issue occurring immediately. About 40 minutes ago I was using 3.4.1 and it was working fine. I'll keep you updated if when I find a solution.
     
  14. danielsonchris

    danielsonchris

    Joined:
    Feb 12, 2011
    Posts:
    43
    Risine,
    When was the last time that you generated your asset bundles? My issue was stashed in the XCode logs:

    I rebuilt my assetbundles and everything started working. Are you seeing anything in your XCode logs that can explain the situation further?
     
  15. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    an important second things on asset bundles, beside the version of unity, is that you also must target them at iOS. if the build script you have in the editor creates it for desktop it won't load on mobile and unless the error changed that would lead to an xcode error saying that its no valid asset bundle or similar
     
  16. danielsonchris

    danielsonchris

    Joined:
    Feb 12, 2011
    Posts:
    43
    Risine, per Dreamora's statement, the editor call must specify the following bold statements at the very least to be loadable via iOS.
    In your build pipeline call:

    BuildPipeline.BuildAssetBundle(null, toinclude.ToArray(),
    path + assetFileName,
    BuildAssetBundleOptions.CollectDependencies,
    BuildTarget.iPhone);
     
  17. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    I got the following error when loading assert bundles:
    I know that the build target is set propper , i just updated unity and im not sure if thats what they mean with
    Edit: ok rebuild the assert bundles in the new unity version works fine : Problem fixed.
     
    Last edited: Oct 27, 2011
  18. Risine

    Risine

    Joined:
    Dec 10, 2009
    Posts:
    154
    Ok, here are some info concerning my app :

    1/ I was on Unity 3.4.1f5, I am now on 3.4.2f2, but problems are the same. ( I created from scratch the bundles with the new unity version ).
    2/ To create the bundles, I'm using : BuildPipeline.BuildAssetBundle(null, objs, path + s1 + ".asb", BuildAssetBundleOptions.CompleteAssets, BuildTarget.iPhone);
    3/ I think the bundles are loaded on Iphone device ( in the Raw directory ) but I receive those warnings when launching the app :
    2011-10-27 10:53:48.769 MyApp[248:307] Received memory warning. Level=2
    WARNING -> applicationDidReceiveMemoryWarning()

    Therefore I suppose it 's some kind of memory issue, but as I said in a previous post, I'm not loading tens of Mb but hundred Kb, so that seems strange it does not work. ( it works when I use the Resources.Load() method instead ).
     
  19. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    I need to scrub through a catalog of 500 pages.
    Every page is 3mb im memory
    Im using a cashing system to get the new images before needed.

    I cash current 12 pages (2 for the current view and 5 in each direction) and 500 X 48kb thumbnails.

    The total object count is 1285 an the memory usage is at 288MB

    thumbnails: 500 X 48kb = ca 25MB
    +
    pages: 12 X 3MB = 36MB
    ======
    61MB
    Ok in addition i have 2 lowPoly models noting special.


    61MB for textures (lets say 70MB for menus items and so on) are someting different then 288MB.

    I need some tips to find the bad boys that are stealing my memory.
     
  20. chiodo80

    chiodo80

    Joined:
    Nov 19, 2011
    Posts:
    3
    Hi!
    I've similar problem but I'm trying to load an assetbundle from iOS App's Documents folder.
    This is the code:

    Code (csharp):
    1.  
    2. var urlFile = "file://" + GetiPhoneDocumentsPath() + "/savedassetbundle.assetbundle";
    3.     Debug.Log("---> loading file from: " + urlFile);
    4.  
    5.     downloadFile = new WWW (urlFile);
    6.  
    7.     yield downloadFile;
    8.  
    9. var assetBundleFile  = downloadFile.assetBundle;
    10. if(assetBundleFile==null)
    11. {
    12.     Debug.Log("---> file not found");
    13.     return;
    14. }
    15.    
    16. var go : Object = assetBundleFile.Load("Cube");
    17.        
    18.         if (go != null)
    19.         {
    20.             var instanced = Instantiate(go);
    21.                
    22.         }
    23.         else
    24.             Debug.Log("Couldnt load resource");
    25.  
    and this is what i get:

    Code (csharp):
    1.  
    2. //I write this line from Debug console
    3. ---> loading file from: file:///Users/myusername/Library/Application Support/iPhone Simulator/5.0/Applications/AE459D8B-1511-4D07-8260-DD5117E08D8D/tmp/savedassetbundle.assetbundle
    4.  
    5. (Filename: /Applications/buildAgent/work/842f9557127e852/Runtime/ExportGenerated/iPhoneSimulatorPlayerUnityLib/UnityEngineDebug.cpp Line: 34)
    6.  
    7. -> force accelerometer registration
    8. -> applicationDidBecomeActive()
    9. Failed to load asset bundle
    10.  
    11. (Filename: /Applications/buildAgent/work/842f9557127e852/Runtime/Misc/AssetBundleUtility.cpp Line: 185)
    12.  
    The filepath seems fine to me.
    Any ideas?
     
  21. ddt

    ddt

    Joined:
    Sep 14, 2010
    Posts:
    8
    I'm very familiar w/ out AssetBundles work, but I want something better.

    I'm using them to store individual PNG's, because I need to both load them into memory and turn them into an uploaded texture to the GPU, all asynchronously.

    I've learned that I can't do that latter part asynchronously any other way, but unfortunately, the process of building an AssetBundle seems to require "importing" it into a format that swells up the size. These PNG's are HUGE, as I'm trying to support the iPad3, and that space is super costly.

    Is there some way I can get a PNG from storage to GPU as an ARGB32 asynchronously w/o going through the importing process? Or is there some magic I can do in the importing process to tell it to leave the asset alone? I've noticed that the Unity engine is linked with libpng, so it stands to reason I should be able to do that.

    Thanks!

    ddt@davetaylor.name
     
  22. TenshiYuna

    TenshiYuna

    Joined:
    Mar 10, 2011
    Posts:
    12
    Hi guys.
    I've tried everything I saw on this and other post but I still get this error.

    force accelerometer registration
    Failed to load asset bundle
    UnityEngine.WWW:get_assetBundle()
    CharacterGenerator:get_ReadyToUse()
    <Start>c__Iterator0:MoveNext()

    I've made sure that my buildtarget is iphone. I imported my folder to my xcode app, (both by drag drop and "add file to..." ) my assets are there, I can see them. I'm using this loading path:

    strPath = "file://" + Application.dataPath + "/../assetbundles/CharacterElementDatabase.assetbundle";

    I'm not sure what I'm doing wrong. Any ideas?
     
  23. mannu55

    mannu55

    Joined:
    Jul 6, 2012
    Posts:
    1
    Danielsonchris is right and helped me a lot!

    I have used web method in which : I used web path in place of local asset bundle path : http://www.pathtomyserver.com/folder/assetbundle

    and very import changed : BuildPipeline.BuildAssetBundle(o, null, CreateAssetbundles.AssetbundlePath + "CharacterElementDatabase.assetbundle", BuildAssetBundleOptions.CollectDependencies,BuildTarget.iPhone);

    reason : :http://docs.unity3d.com/Documentation/ScriptReference/AssetBundle.html
    Note : that bundles are not fully compatible between platforms. A bundle built for any of the standalone platforms (including webplayer) can be loaded on any of those platforms but not on iOS or Android. Furthermore, a bundle built for iOS is not compatible with Android and vice versa.
     
  24. VincentDB

    VincentDB

    Joined:
    Sep 16, 2013
    Posts:
    1
    Hi everyone, i use this old thread because i got the same problem than you but no solutions works for me.

    I have an asset bundle file created with iOS device, and i want use it in my iOS game but i can't load it. I use this method:
    First, i add my folder "assetbundles" who contain my .assetbundle file in Xcode with same import parameters used here.
    Then i import my assetbundle with www method with the path:
    url = "file://" + Application.dataPath + "/../assetbundles/Mybundle.assetbundle";

    My bundle work fine (tested with local desktop path in unity in iOS device) but i can't access him in my iPad, i got the following error:
    "You are trying to load data from a www stream which had the following error when downloading.
    unsupported URL
    UnityEngine.WWW:get_assetBundle()
    <downloadAssetBundle>c_Iterator0:MoveNext()

    [/Applications/buildAgent/work/cac08d8a5e25d4cb/Runtime/Misc/WWWCached.cpp line 265]
    (Filename: /Applications/buildAgent/work/cac08d8a5e25d4cb/Runtime/Misc/WWWCached.cpp Line: 265)

    Please help me, i'm looking solutions since many hours...
    Thanks in advance.
     
    quile likes this.
  25. quile

    quile

    Joined:
    Nov 3, 2015
    Posts:
    1
    You are trying to load data from a www stream which had the following error when downloading.

    unsupported URL

    Who fix this error? pls help give some advice ?

    Thanks so much ......
     
  26. chimmie40

    chimmie40

    Joined:
    Dec 10, 2019
    Posts:
    1