Search Unity

Loading wasm with WebAssembly.instantiateStreaming

Discussion in 'Web' started by traden, Jan 4, 2019.

  1. traden

    traden

    Joined:
    Sep 16, 2009
    Posts:
    65
    I'm looking at bypassing the need for UnityLoader, and any other non- .wasm file for that matter. I know that the wasm is compiled with Emscripten, but it should still be possible for me to use the latest webassembly calls for loading the content should it not? As per:

    https://developer.mozilla.org/en-US/docs/WebAssembly/Loading_and_running

    I have the mime type set correctly to => ('Content-Type', 'application/wasm')

    Trying to load both the build.wasm.code.unityweb + build.wasm.framework.unityweb but I get this error
    Wasm decoding failed: expected magic word 00 61 73 6d, found 1f 8b 08 18 @+0

    It looks like the .wasm binary should start with 00 61 73 6d (\0asm) but doesn't


    any ideas?
    Thanks!
     
    Last edited: Jan 5, 2019
  2. traden

    traden

    Joined:
    Sep 16, 2009
    Posts:
    65
    Follow up,

    I know Project Tiny doesn't compile to a .wasm just yet but that's the end goal, is there any plans on merging the two projects so we can have a lighter wrapper for the .wasm? Or maybe no wrapper at all if we chose and a straight .wasm fine is generated with imports /exports?
     
  3. traden

    traden

    Joined:
    Sep 16, 2009
    Posts:
    65
    It looks like wasm streaming has been added in the latest alpha, just not having much luck getting it to run.
     
  4. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    non-development builds will produce compressed unityweb files (if compression is enabled). So, you need to configure the headers accordingly (see WebGL: Deploying compressed builds) so that the browser will decompress them on download. Note that the UnityLoader provides a software decompression fallback.
     
  5. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    streaming instantiation also requires you to configure the server. For Apache you will need something like:
    Code (csharp):
    1. <IfModule mod_mime.c>
    2.   AddEncoding gzip .unityweb
    3.   AddType application/wasm .wasm
    4.   AddEncoding gzip .wasm
    5.   AddOutputFilterByType DEFLATE application/wasm
    6. </IfModule>
    replace gzip with br, if using Brotli.
     
    lindybrits and n0rvig like this.
  6. traden

    traden

    Joined:
    Sep 16, 2009
    Posts:
    65
    Much appreciated Marco!

    Thank you
     
  7. CodeInMotion

    CodeInMotion

    Joined:
    Jun 1, 2018
    Posts:
    10

    where do i put this?

    I am going through similar posts for hours.. they talk about adding code, but no post tells where to add this code. which file is this?
     
  8. gtk2k

    gtk2k

    Joined:
    Aug 13, 2014
    Posts:
    288
    httpd.conf file
     
  9. CodeInMotion

    CodeInMotion

    Joined:
    Jun 1, 2018
    Posts:
    10
    Thank you. I just added the above code to the httpd.conf file. no change. I still get the same errors.

    when i stop and start the apache server, i get errors. the server doesn't start.

    This is quite frustrating for me, the last time i made a web build was like 2 weeks ago and it worked perfectly. now all settings are the same for my new project but i can't run the build. been at it for more than 36 hours and have scoured forums, stack overflow, reddit and all. nothing seems to work.

    is this a unity bug?
     
  10. gtk2k

    gtk2k

    Joined:
    Aug 13, 2014
    Posts:
    288
    If you get an error in httpd.conf, try reverting httpd.conf and adding it to your .htaccess file
     
  11. CodeInMotion

    CodeInMotion

    Joined:
    Jun 1, 2018
    Posts:
    10

    havent been able to find the .htaccess file either.
     
  12. staqchani512

    staqchani512

    Joined:
    Nov 18, 2021
    Posts:
    2
    Hi, I'm using aws server for my game which is using web streaming files. aws server uses linux based nginx server. how i configure my mime type file to rid of mime type error?