Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

WebGL Streaming Instantiation Support - Errors on Loading in Browser

Discussion in '2019.1 Alpha' started by JJJohan, Nov 15, 2018.

  1. JJJohan

    JJJohan

    Joined:
    Mar 18, 2016
    Posts:
    131
    I was excited to see that in Unity 2019.1 Alpha 9, WebGL now has an option to enable Wasm streaming instanation. However it looks like there's a bit more involved than simply ticking the box in the player settings to have it working.

    Simply uploading the output files results in the bellow console output:

    Code (JavaScript):
    1. wasm streaming compile failed: TypeError: Response has unsupported MIME type
    2.  
    3. falling back to ArrayBuffer instantiation
    4.  
    5. on the web, we need the wasm binary to be preloaded and set on Module['wasmBinary']. emcc.py will do that for you when generating HTML (but not JS)
    6.  
    7. failed to asynchronously prepare wasm
    8.  
    9. uncaught exception: abort("abort(\"on the web, we need the wasm binary to be preloaded and set on Module['wasmBinary']. emcc.py will do that for you when generating HTML (but not JS)\")
    Unfortunately the ArrayBuffer fallback appears to simply fail.

    Reading the WebAssembly spec as well as the Emscripten compile instructions, it appears that for streaming instantiation to work the files need to have their Content-Type set on the server as application/wasm. Sadly this doesn't appear to change the outcome.



    @Marco-Trivellato would you have any suggestions?

    I suspect Amazon S3 isn't serving the Content-Type header correctly.. Other headers (e.g. Content-Encoding gzip) behave correctly.
     
    Last edited: Nov 15, 2018
  2. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,619
    Hi @JJJohan,

    To be honest, I only tested it on our self hosted apache server so far, see this build. Basically you need to add .wasm to the mime types and make sure it's configured according to the compression selected in PlayerSettings.WebGL.compression.
    For brotli, the .htacces looks like:
    Code (csharp):
    1.  
    2. <IfModule mod_mime.c>
    3.   AddEncoding br .unityweb
    4.   AddType application/wasm .wasm
    5.   AddEncoding br .wasm
    6.   AddOutputFilterByType DEFLATE application/wasm
    7. </IfModule>
    similarly, for gzip:
    Code (csharp):
    1.  
    2. <IfModule mod_mime.c>
    3.   AddEncoding gzip .unityweb
    4.   AddType application/wasm .wasm
    5.   AddEncoding gzip .wasm
    6.   AddOutputFilterByType DEFLATE application/wasm
    7. </IfModule>
    So for IIS you need to do something similar. We will try to update the docs as soon as possible.

    One known issue is that we are not currently caching the wasm file but this should be fixed in the coming weeks.

    Thanks for being an early adopter :)
     
    JJJohan likes this.
  3. AlexHell

    AlexHell

    Joined:
    Oct 2, 2014
    Posts:
    90
    I can't build webgl in 2019.1 - alpha 12 - it freezes on build

    I need to know - is it work? Is it help with background (un-focused tab) download and initialize webgl, and not freezes for user focus (unity 5.6 and 2017 is freeze before final init, and wait for user focus tab)
     
  4. traden

    traden

    Joined:
    Sep 16, 2009
    Posts:
    59
    I managed to get the mime type error fixed (running Express server). But I'm still getting magic word errors. CompileError: AsyncCompile: Wasm decoding failed: expected magic word.

    This is happening now when I just do a standard ctrl+b local build now as well with WebAssembly streaming. As Alex stated, basic local builds are no longer functional.
     
  5. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,619
    This is a known issue that we aim to fix before releasing 2019.1. Here is the issue tracker.
     
  6. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,619
    This is not a known issue. Unity 2019.1.0a13 is out now, would you mind trying with that?

    If you are referring to the freeze at the very end of loading, it is not fixed by wasm streaming.
     
  7. AlexHell

    AlexHell

    Joined:
    Oct 2, 2014
    Posts:
    90
    I mean 5 sec freeze (in Firefox.. GIF animation is freezed too) (or 10 sec in chrome) at the end, after preInit and till onRuntimeInitialized on Module object (I have write logs and checked this at unity 5.6.)