Search Unity

  1. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  2. Unity 2017.2 is now released.
    Dismiss Notice
  3. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  6. Unity 2017.3 beta is now available for download.
    Dismiss Notice

Asset Bundles failing to load (on iOS)

Discussion in 'iOS and tvOS' started by Evan-Greenwood, Feb 12, 2011.

  1. Evan-Greenwood

    Evan-Greenwood

    Joined:
    Aug 6, 2008
    Posts:
    96
    edit: I've solved this now I think. What I had done wrong was create the assets badly. I don't know the exact reasons, but taking the standard unity export asset bundle script and adding the BuildTarget.iPhone (I had originally left out a couple important parameters)

    I've included some asset bundles in the "StreamingAssets" folder. They load fine in the editor, but, although I believe I have their path correct, they fail in iOS.

    If I build the asset bundles with their target set to WebPlayer I get this error from the device:

    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/f724c1acfee760b6/Projects/../Runtime/Serialize/SerializedFile.cpp Line: 210)

    The asset bundle 'file:///var/mobile/Applications/5AB67DD7-DDA0-44EA-8E6E-DBCDE54E18E2/prpg.app/Data/Raw/AssetBundles/LevelGeneratorCrypt1.unity3d' can't be loaded because it was not built with the right version or build target.

    But when I build them with their bundles set to iPhone the device just says : Failed to load Asset Bundle. And it does not tell me why.

    I'm going to try exporting Asset Bundles in different ways, see if I get lucky.

    But does anyone know what am I missing? Is there a guide to getting Asset Bundles working in iOS? (I'm pretty certain I've got the dataPath correct)
     
    Last edited: Feb 12, 2011
  2. Evan-Greenwood

    Evan-Greenwood

    Joined:
    Aug 6, 2008
    Posts:
    96
    My problem was quite bizarre in the end, actually probably a bug in Unity:

    This works:
    Code (csharp):
    1. [MenuItem("Assets/Build AssetBundle From Selection - Track dependencies iPhone")]
    2.     static void ExportAssetBundleIOSComplete() {
    3.         // Bring up save panel
    4.         string path = EditorUtility.SaveFilePanel("Save Resource", "", "New Resource", "unity3d");
    5.         if (path.Length != 0) {
    6.             // Build the resource file from the active selection.
    7.             //
    8.             Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
    9.             //
    10.             BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets, BuildTarget.iPhone);
    11.             Selection.objects = selection;
    12.             //
    13.         }
    14. }
    While this creates a Asset Bundle that can't be loaded from iOS (the only difference being it does not get a path from the save panel):
    Code (csharp):
    1.   [MenuItem("Assets/Build AssetBundle From Selection - Track dependencies iPhone (no prompt)")]
    2.     static void ExportAssetBundleIOSCompleteNoPrompt() {
    3.         // Do not bring up save panel
    4.         string path = Application.dataPath + "/StreamingAssets/AssetBundles/" + Selection.activeObject.name + ".unity3D";
    5.         if (path.Length != 0) {
    6.             // Build the resource file from the active selection.
    7.             //
    8.             Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
    9.             //
    10.             BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets, BuildTarget.iPhone);
    11.             Selection.objects = selection;
    12.             //
    13.         }
    14. }
    Also it looks like Asset Bundles have a large memory overhead, so the whole affair was quite futile in the end.
     
  3. kablammyman

    kablammyman

    Joined:
    Nov 22, 2010
    Posts:
    500
    thanks for this information. Im testing this now for android (using the android build target for the assets) so hopefully this ends a problem i was having.
     
  4. sandworm

    sandworm

    Joined:
    Aug 11, 2009
    Posts:
    210
    Thank you very much Evan, you just saved my bacon!
     
  5. VamshiKrishnaP

    VamshiKrishnaP

    Joined:
    Jan 17, 2013
    Posts:
    16
    The above code is working properly in iphone.
    Can anyone help me , how to create asset bundle for Android ?

    Thanks in advance.
     
  6. UnityCoder

    UnityCoder

    Joined:
    Dec 8, 2011
    Posts:
    532
    @VamshiKrishnaP,

    just change build target to android.
     
  7. VamshiKrishnaP

    VamshiKrishnaP

    Joined:
    Jan 17, 2013
    Posts:
    16
    ok i will try with this. thank you @UnityCoder
     
  8. VamshiKrishnaP

    VamshiKrishnaP

    Joined:
    Jan 17, 2013
    Posts:
    16
    working. thank u coder
     
  9. VamshiKrishnaP

    VamshiKrishnaP

    Joined:
    Jan 17, 2013
    Posts:
    16
    @unitycoder are you from india ? from where ?
     
  10. UnityCoder

    UnityCoder

    Joined:
    Dec 8, 2011
    Posts:
    532
    @Vamshi
    Yes i am from India and please check pm