Unity Community


Results 1 to 10 of 10

  1. Location
    South Africa
    Posts
    96

    Asset Bundles failing to load (on iOS) [solved]

    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 by Evan.Greenwood; 02-12-2011 at 02:01 AM. Reason: Solved


  2. Location
    South Africa
    Posts
    96
    My problem was quite bizarre in the end, actually probably a bug in Unity:

    This works:
    Code:  
    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:  
    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. Location
    san francisco, ca
    Posts
    466
    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. Location
    Anchorage, Alaska
    Posts
    193
    Thank you very much Evan, you just saved my bacon!


  5. Posts
    8
    The above code is working properly in iphone.
    Can anyone help me , how to create asset bundle for Android ?

    Thanks in advance.


  6. Location
    India
    Posts
    524
    @VamshiKrishnaP,

    just change build target to android.


  7. Posts
    8
    ok i will try with this. thank you @UnityCoder


  8. Posts
    8
    working. thank u coder


  9. Posts
    8
    @unitycoder are you from india ? from where ?


  10. Location
    India
    Posts
    524
    @Vamshi
    Yes i am from India and please check pm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •