Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

WebGL Asset Bundles

Discussion in 'Unity 5 Pre-order Beta' started by sluice, Oct 27, 2014.

  1. sluice

    sluice

    Joined:
    Jan 31, 2014
    Posts:
    416
    Normally for exporting WebPlayer asset bundles we would use:
    the extension .unity3d, and
    the BuildTarget.WebPlayer
    Code (csharp):
    1. string[] levels = new string[] {"Assets/Level1.unity"};
    2. BuildPipeline.BuildStreamedSceneAssetBundle( levels, "Streamed-Level1.unity3d", BuildTarget.WebPlayer);

    But For WebGL, is it?
    Code (csharp):
    1. string[] levels = new string[] {"Assets/Level1.unity"};
    2. BuildPipeline.BuildStreamedSceneAssetBundle( levels, "Streamed-Level1.unity3d", BuildTarget.WebGLPlayer);
    3.  
    Does the file extension still remains .unity3d ?
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    The extension is not important for asset bundles. You can pick whichever you like or none at all.
     
  3. sluice

    sluice

    Joined:
    Jan 31, 2014
    Posts:
    416
    Ok, so only setting the correct BuildTarget is important?
    In my case, for WebGL: BuildTarget.WebGLPlayer
     
  4. RalphH

    RalphH

    Administrator

    Joined:
    Dec 22, 2011
    Posts:
    592
    Correct.
     
  5. sluice

    sluice

    Joined:
    Jan 31, 2014
    Posts:
    416
    Ok, so now, I am trying to load my scene. Here is the script I am using.
    Code (csharp):
    1. IEnumerator LoadSceneWebGL(string scene)
    2. {
    3.     download = new WWW ("./AssetBundles/"+scene+".unity3d");
    4.     while(!download.isDone)
    5.     {
    6.        //here I update my preloader progress bar...
    7.         yield return null;
    8.     }
    9.     yield return download;
    10.  
    11.     assetBundle = download.assetBundle;
    12.    
    13.     Application.LoadLevel(scene);
    14.  
    15.     yield return true;
    16. }
    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:
     
  6. sluice

    sluice

    Joined:
    Jan 31, 2014
    Posts:
    416
    Also, when trying to log the asset bundle name, after the download is finished returns nothing.
    Code (csharp):
    1. //these two alert methods returns nothing.
    2. Application.ExternalCall("alert",  download.assetBundle.name);
    3. //and
    4. Application.ExternalCall("alert", assetBundle.name);  
    5.  
     
  7. GabrieleUnity

    GabrieleUnity

    Unity Technologies

    Joined:
    Sep 4, 2012
    Posts:
    116
    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.
     
  8. RalphH

    RalphH

    Administrator

    Joined:
    Dec 22, 2011
    Posts:
    592
    For reference, here is what the UI looks like and what it should be set too. Make sure you make a development build.
     

    Attached Files:

  9. sluice

    sluice

    Joined:
    Jan 31, 2014
    Posts:
    416
    @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();
    Code (csharp):
    1. function jsStackTrace() {
    2.   var err = new Error();
    3.   if (!err.stack) {
    4.     // IE10+ special cases: It does have callstack info, but it is only populated if an Error object is thrown,
    5.     // so try that as a special-case.
    6.     try {
    7.       throw new Error(0);
    8.     } catch(e) {
    9.       err = e;
    10.     }
    11.     if (!err.stack) {
    12.       return '(no stack trace available)';
    13.     }
    14.   }
    Not really of much help...
     
    Last edited: Oct 28, 2014
  10. RalphH

    RalphH

    Administrator

    Joined:
    Dec 22, 2011
    Posts:
    592
    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.
     
  11. sluice

    sluice

    Joined:
    Jan 31, 2014
    Posts:
    416
    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.
     
    Last edited: Oct 29, 2014