www.assetBundle is null only on iOS device

Hello,

I’ve a issue on running my game on iOS device that doesn’t occur in editor. I’ve encounter this problem since I update to Unity 4.3.3 (I was on Unity 4.3.0 before or 4.3.1, I’m not sure about it).

I used asset bundles that are downloaded with WWW object.
Here is my sample of code downloading the bundle (wich contains a scene).

IEnumerator StartDownloadScene(string url)
{
        WWW download = new WWW(url);
        yield return download;
        
        if (!string.IsNullOrEmpty(download.error))
        {
            Application.LoadLevel("NotAvailable");
        }
        while (download.isDone == false)
        {
            yield return null;
        }
        if(download.assetBundle == null)
        {
            Debug.LogError(url+" has no asset bundle");
        }
        Debug.LogError("progress : +"download.progress);
}

When I execute my game from Unity Editor (on Mac OS X), no problem : my asset bundle is loaded, without error and the value of download.assetBundle is not nulland progress is 100% .

However, when I execute the game on iPad from XCode, download.assetBundle is null and progress is 0% (only 13 KB downloaded on 3.4MB).

But it is exactly the same file I download, and I packed the asset bundle with iOS as target plateform.
Here is the code I use to do that (in a script editor) :

	static void BuildAssetBundle(BuildTarget target)
	{
		string assetPath = AssetDatabase.GetAssetPath(Selection.activeObject);
		
		//make sure user has a scene selected:
		if (Selection.objects.Length != 1 || !assetPath.Contains(".unity"))
		{
			EditorUtility.DisplayDialog("Scene Asset Bundle Creation", "Please select a single scene in your project.", "OK");
			return;
		}

		//set a save location for the bundle:
		string savePath = EditorUtility.SaveFilePanel("Save Scene Asset Bundle for "+ target.ToString(), "", "Scene_"+target.ToString(), "unity3d");
		if (savePath == "")
		{
			return;
		}

		//save asset bundles for iphone and android:
		string[] pathPieces = savePath.Split('.');

        BuildPipeline.BuildStreamedSceneAssetBundle(new string[] { assetPath }, savePath, target);
		
		//complete:
		EditorApplication.Beep();
        EditorUtility.DisplayDialog("Scene Asset Bundle Creation" , "Scene asset bundle built for " + target.ToString(), "OK");
	}

And here is the call of this function :

BuildAssetBundle(BuildTarget.iPhone);

I tried to rebuild asset bundle with Unity 4.3.3 but it doesn’t solve the probleme.

All of this was good in november the last time I work on my game.
The file exists, the download.isDone valuye is true, but progress is 0 ans assetBundle is null. I don’t understand what I miss.
I try on two different iPad (iPad 4 and iPad 2) with the same issue.

Is there new features for Asset Bundle that I have missed ? Something in creating or downloading asset Bundle I did wrong ?

Thank you for your answers !


UPDATE : Solved with Unity 4.3.4

We have exactly the same problem, but only with the first loading. We use WWW.LoadFromCacheOrDownload for download the assetbundle and access the assetbundle when the download is done. With Unity 4.3.2 this worked nicely and we had no problems, but with Unity 4.3.3 the assetbundle is null on the first load, but present on the second loading.

We’re seeking a solution for this problem too, so if anyone of Unity can maybe explain what change was intruduced to the WWW class for iOS it would be appriciated!

Ok, I can now confirm that there is definately a bug for iOS.

I created a test project and the first download of the assetbundle returned always null for the assetbundle. When downloading the same assetbundle again, the assetbundle was downloaded successfully. In the editor the same procedure was always successful.

Create also a bug ticket: http://fogbugz.unity3d.com/default.asp?586545_eqff4its4gvcqrib

Thank you for all these precious informations !
So, the best way to “hack” this until the bug is corrected is to re-download the asset bundle after the first download ?

Something like this I suppose (based on the sample on my first post) ?

IEnumerator StartDownloadScene(string url)

{

        WWW download = new  WWW.LoadFromCacheOrDownload(url);

        yield return download;

        
        if (!string.IsNullOrEmpty(download.error))

        {

            Application.LoadLevel("NotAvailable");

        }

        while (download.isDone == false)

        {

            yield return null;

        }

        if(download.assetBundle == null)

        {

            Debug.LogError(url+" has no asset bundle");
            download = new  WWW.LoadFromCacheOrDownload(url);
            yield return download;      

            if (!string.IsNullOrEmpty(download.error))
            {
                Application.LoadLevel("NotAvailable");
            }

            while (download.isDone == false)
            {
                yield return null;
            }

        }

        Debug.LogError("progress : +"download.progress);

}

Yes, it seems like. Still this is a very dirty hack and I would appriciate an explation from a Unity developer what was changed in the WWW class and if we could fix it maybe on our own (the WWW class seems to be available in the xcode project now) or give out a hot fix.

From the issue trackers note:

I hope that a fix won’t take too long and that Unity will release a hotfix for that. We can’t upload a new release version with such a bug in or having to download the assetbundles all the time (about 20 mb which the client has to download then everytime…).

Strange because I’ve tested with WWW constructor (as describe in my first post) and that’s how I’ve encounter this problem. :face_with_spiral_eyes:

I hope Unity support can solve this shortly !

Ok, good to know. We’re using the “hack” by downloading it twice.

This is what I got as a response, which is a good message. Let’s hope that the hotfix version won’t take too long.

Posting here to hopefully be notified when the hotfix comes out cuz we’re hitting this sucka too!

PING

Need this fixed too. Unable to update to 4.3.3 until this is taken care of. :sad:

I tried the “double download” but even the second time www.assetBundles is null again.
I think I’ll go back to Unity 4.3.2 until the fix is available.

well, this is plain wrong. Alas, there is no real workaround for now (only possible half-measures), but we are prepping hotfix

Alexey - thank you for the response and for letting us know you are prepping a hotfix. Any chance you can comment on an ETA for the hotfix? Nothing specific… just like: “within a week”, “within a month”, “next year” or “in your dreams”?

LOL

I see. The problem is that it “could” work simply by retrying to download again until the data is fetched. We’re downloading an assetbundle with about 50 KB size and there it works, but we also have an assetbundle with 4 MB where it doesn’t work (well, it works if we keep trying to download again till the 4 MB are downloaded, then the next download is a success).

I assume the “workaround” should be for some small data which should be loaded and not necessarily be cached. So for now, we need this hotfix. Thanks Alexey for pointing that out. A ETA would be nice o’course :smile:

Just wanted to say I’m getting this bug as well, only on iOS and only since upgrading to 4.3 (I went straight from 4.2 to 4.3.3). I retry 100 times and randomly it works. Also about 10% of the URLs I’m hitting work but the vast majority just return instantly with no error message but with empty data.

please fix asap!

do we have a rough eta? i want to know if i should downgrade or if we can wait before we do our next release of our game.

Hi,

Same here: download and load bundleAsset is a main part of my program. So I’m really stuck. I suspect the problem is global on WWW class. Here is my code:

WWW wwwDownload = new WWW(url);
while(!wwwDownload.isDone)
{
        int progress = Mathf.RoundToInt(wwwDownload.progress * 100f);
        LblProgress.Text = "" + progress + "%";
	yield return 0;
}

It worked on IOS/MAC with Unity 4.2, and now, in 4.3.3, it works only on MAC

Any ETA on this ? Seriously, this is a critical issue because there is no mitigation.
AssetBundles is the main reason why I bought Pro Version. If it’s broken on IOS whithout any resolution time, why should I continue to pay ?

For your information, I’ve downgraded Unity on Mac OSX to 4.3.2 and the problems does not occure.
I’m still using Unity 4.3.3 on my PC, but I think wait the next update for Unity on Mac OSX.

Unity 4.3.2 (and older) can be downloaded here : http://unity3d.com/unity/download/archive