WebGL Asset Bundles

Normally for exporting WebPlayer asset bundles we would use:
the extension .unity3d, and
the BuildTarget.WebPlayer

string[] levels = new string[] {"Assets/Level1.unity"};
BuildPipeline.BuildStreamedSceneAssetBundle( levels, "Streamed-Level1.unity3d", BuildTarget.WebPlayer);

But For WebGL, is it?

string[] levels = new string[] {"Assets/Level1.unity"};
BuildPipeline.BuildStreamedSceneAssetBundle( levels, "Streamed-Level1.unity3d", BuildTarget.WebGLPlayer);

Does the file extension still remains .unity3d ?

The extension is not important for asset bundles. You can pick whichever you like or none at all.

Ok, so only setting the correct BuildTarget is important?
In my case, for WebGL: BuildTarget.WebGLPlayer

Correct.

Ok, so now, I am trying to load my scene. Here is the script I am using.

IEnumerator LoadSceneWebGL(string scene)
{
    download = new WWW ("./AssetBundles/"+scene+".unity3d");
    while(!download.isDone)
    {
       //here I update my preloader progress bar...
        yield return null;
    }
    yield return download;

    assetBundle = download.assetBundle;
   
    Application.LoadLevel(scene);

    yield return true;
}

Unfortunatly, it doesn’t work for me.
I get this error, in both Chrome and Firefox running on local server.

Chrome alert error:

Chrome console log:

Firefox alert error:

Firefox console log:

Also, when trying to log the asset bundle name, after the download is finished returns nothing.

//these two alert methods returns nothing.
Application.ExternalCall("alert",  download.assetBundle.name);
//and
Application.ExternalCall("alert", assetBundle.name);

Hello sluice,

you can get more details about the exception being thrown by enabling exceptions in your WebGL build.
To enable exceptions:

  • open Build Settings
  • select WebGL
  • click “Player Settings”
  • in the inspector, click “Publishing Settings”
  • set Enable Exceptions to a value different than none

Than recompile and run again.

Give it a try, it should give us more info to understand the problem.

For reference, here is what the UI looks like and what it should be set too. Make sure you make a development build.

1826718--117028--Screenshot 2014-10-28 10.05.20.png

@GabrieleUnity , @RalphH ,
I already have my exceptions set to SoftNullReferenceExceptions.

The complete errors is:

Then looking at that first error hint, in route1webgl.js:978:13,
the error is var err = new Error();

function jsStackTrace() {
  var err = new Error();
  if (!err.stack) {
    // IE10+ special cases: It does have callstack info, but it is only populated if an Error object is thrown,
    // so try that as a special-case.
    try {
      throw new Error(0);
    } catch(e) {
      err = e;
    }
    if (!err.stack) {
      return '(no stack trace available)';
    }
  }

Not really of much help…

that stack trace doesn’t seem to imply anything related to the assetbundle loading, as far as I can see. Rather, it is happening by an instantiate call in TilesCoinsIntegrator::InstantiateCoins. However, it does look like it is an issue with either a null reference or something going wrong in the instantiate.

With a different scene (without any TilesCoinsIntegrator stuff), It finally loads!
funny thing is the AssetBundle name returned is " ".

Now, I have to figure out why there is a problem with my other scene (most probably TilesCoinsIntegrator like you said.)
The weird thing is the scene doesn’t return any error when run alone as a build.
As with loading it as an asset, it works fine in WebPlayer, Flash and StandAlone.