Download AssetBundle through WWW Class freezes Unity

I try to download an assetBundle from server through WWW Class like this:

WWW download = new WWW ("https://myserver/scene1.unity3d");

But Unity freezes at this point. The assetBundle is created with this code:

string[] level1 = new string []{"Assets/Scenes/scene1.unity"};
BuildPipeline.BuildStreamedSceneAssetBundle( level1 , "Assets/Bundles/scene1.unity3d", EditorUserBuildSettings.activeBuildTarget);

I know I can use LoadFromCacheOrDownload and this works, but why it is not working with the WWW Class method? Other file types like .mp4 or .txt I can easily download, but not the assetbundles created with BuildPipeline.BuildStreamedSceneAssetBundle. Also Unity freezes when I try downloading assetbundles created by Unitys new assetbundles system and the method BuildPipeline.BuildAssetBundles. I have tested on Unity 5.2, 5.3 and 5.4.

when you download an asset with WWW Unity will wait until the operation is complete… try to download the WWW inside a coroutine and waiting for it to complete by using events so you do not use Unity’s main thread.

1 Like

I forgot to mention that I do that inside a coroutine, but even a Debug.Log(“Test”) after new WWW(“https://myserver/scene1.unity3d”) is never called and Unity freezes.

have you checked if the game is actually downloading from the WWW?

var www = new WWW(url);
while (!www.isDone)
{
    print(www.progress);
    yield return null;
}

Using it like this should allow you to get any status you want in each iteration.

Thank you it is working, my mistake was I forgot the “yield return null” inside the while-Loop

Glad I could help.

Could some moderator close this one please :wink: