Failed to load assetbundle :(

Hi,

I’m having some problems with loading assetbundles on IOS, in the editor it works though. I’m using Unity 4.0 and i’m loading a .unity3d assetbundle file with animation clips inside. I placed the assetbundle in the Assetbundles folder so path on Mac is Assets/Assetbundles/Backanim.unity3d

XCode error message

Asset bundle creation script

using UnityEngine;
using UnityEditor;
using System.Collections;

public class ExportAssetBundles : MonoBehaviour 
{
	[MenuItem("Assets/Build AssetBundle From Selection")]
	static void ExporResourceNoTrack()
	{
		string path = EditorUtility.SaveFilePanel("Save Resource", "", "New Resource", "unity3d");
		if(path.Length != 0)
		{
			BuildPipeline.BuildAssetBundle(Selection.activeObject, Selection.objects, path, BuildAssetBundleOptions.CollectDependencies, BuildTarget.iPhone);
		}
	}
}

Load assetbundle script

public static var LA : LoadAnimations;

var human : GameObject;
private var anim : UnityEngine.Object[];
private var file : WWW;

function Start()
{
	LA = this;
	human = GameObject.Find("Human");
}

function LoadAnimation()
{
	Debug.Log(Application.dataPath);
	file = new WWW("file://" + Application.dataPath + "/Assetbundles/Backanim.unity3d");
	yield file;
	
	Debug.Log(file.url.ToString());
	
	if(file.error != null)
	{
		Debug.Log(file.error);
	}
	
	anim  = file.assetBundle.LoadAll(AnimationClip);
	
	setAnimations();
	
}

function setAnimations()
{
	//Back animations
	human.animation.AddClip(anim[8], ButtonText5G.BT.backArray[0], 0, 120, false);		
	human.animation.AddClip(anim[0], ButtonText5G.BT.backArray[1], 0, 200, false);			
	human.animation.AddClip(anim[0], ButtonText5G.BT.backArray[2], 250, 425, false);		
	human.animation.AddClip(anim[0], ButtonText5G.BT.backArray[3], 460, 750, false);		
	human.animation.AddClip(anim[0], ButtonText5G.BT.backArray[4], 800, 1000, false);		
	human.animation.AddClip(anim[7], ButtonText5G.BT.backArray[5], 0, 100, false);			
	human.animation.AddClip(anim[1], ButtonText5G.BT.backArray[7], 300, 600, false);		
	human.animation.AddClip(anim[1], ButtonText5G.BT.backArray[8], 700, 900, false);		
	human.animation.AddClip(anim[1], ButtonText5G.BT.backArray[9], 1101, 1250, false);		
	human.animation.AddClip(anim[2], ButtonText5G.BT.backArray[10], 0, 200, false);			
	human.animation.AddClip(anim[3], ButtonText5G.BT.backArray[6], 1, 150, false);			
	human.animation.AddClip(anim[4], ButtonText5G.BT.backArray[12], 1, 125, false);			
	human.animation.AddClip(anim[5], ButtonText5G.BT.backArray[13], 1, 100, false);			
	human.animation.AddClip(anim[6], ButtonText5G.BT.backArray[11], 200, 400, false);		
}

Can someone point out what i’m doing wrong here?

I may be wrong on this, haven’t checked into it in like a year.

But last time I was dealing with assetBundles, unity did not stream the unzipping on iOS. It would have to load the entire zip file in memory and plus some to unzip it. So you could not make large asset bundles, otherwise your device would run out of memory when trying to open them.

Actually now that I look at your code, your not even using that functionality. You are using the function which will unzip the asset bundle and keep the entire asset bundle in memory.

On iOS, I found it best to create uncompressed asset bundles, using this flag:

then load them in with this:

That will basically let you open and close asset bundles with virtually no change in memory usage. Assetbundles work exactly like portable, external, Resources folders when using that method.

Although, actually now that I look at your error closer it says,

The requested URL was not found on this server.
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:Log(Object)
$:MoveNext()

The path specified does not point to an asset bundle.

Your making a very fundamental error in unity. Application.DataPath will not get you access to everything in your ‘Assets’ folder when your running in a build.

Go look at a build of your app at what is actually in this directory: file:///var/mobile/Applications/57E05D91-E61D-4B8E-B511-E73BA09586E6/fysiotherappy.app/Data/Assetbundles/Backanim.unity3d

If you build your app to a .ipa, you can rename .ipa to .zip and then unzip and actually look in that Data folder.

Which you won’t find the conents of the Assets folder as it is in the unity editor. You will find compressed packages of assets and mono libraries.

Unity only includes things from the Assets folder if they are included in a scene, which it then packs into a special format and puts in the Data folder. Or if assets are placed in the Resources folder it will include them too, but in that case you can only get to those through Resources.Load

Ideally, what you should do with assetbundles is set it up so your assetbundles are written out to a location outside of your Assets folder, there is no reason to ever put an assetbundle in the Assets folder.
And then rsync those asset bundles into your ipa through a runtime script in the build phases of Xcode. This is a little advanced, but you can decipher it if you google those words.

However, for the sake of just getting this working, there is a quicker way. Go into your iOS build folder, as in, go into the folder that Unity generates the XCode project in and all of it’s associated data. Inside of the folder is a ‘Data’ folder. Copy your ‘AssetBundles’ folder from your Assets folder into that Data folder. Unity builds the project with a script to automatically copy that Data folder to your ipa on build, so if you place your ‘AssetBundles’ folder in that data folder, then it will be copied, and it will then be able to find your asset bundle.