August 30, 2016

Solve the Uncaught unknown compression method Unity WebGL error

This Sunday I had to finish a silly game called Traffic Light Simulator for the Ludum Dare competition.


One of the many problems I encountered happened when I tried to upload the first version of the game to my server. As you may know, Unity has abandoned the WebPlayer option in favor of the WebGL option, which is under development so there will be bugs! It was always super-easy to make the WebPlayer option work online, but with each Unity update you have to learn a new way to make the WebGL option work.

First of all, the offline version worked fine in Firefox, but when uploaded the project to the server I got the following error:
An error occured running the Unity content on this page. See your browser's JavaScript console for more info. The error was: Uncaught unknown compression method.

When you open the Developer Tools console, you will see the following:
  • Failed to load resource: the server responded with a status of 404 (Not Found): Invoking error handler due to Uncaught unknown compression method
  • Uncaught unknown compression method
  • Failed to load resource: net::ERR_CONNECTION_RESET: Could not download Release/Test.datagz
  • Failed to load resource: net::ERR_CONNECTION_RESET: Could not download Release/Test.jsgz
  
So what do you do when you encounter an error you have't seen before? You google it! And if you google these errors you will find a lot of people with the same problem. The solution seems to be to modify the .htaccess file. But in the latest version of Unity, there's no .htaccess file in the WebGL folder! The second link on Google was Unity's own documentation, which is not updated to the latest version which is 5.4, so there was no solution there either. Another solution was to contact the server provider.

After digging around on the web, I found the solution, and it was this super easy solution: What you need to do is to modify the index.html, which is the only file in the WebGL folder. So open it in Notepad or whatever program you are using. At the bottom of the file, you will see the following lines:
  • dataUrl: "Release/Test.data", 
  • codeUrl: "Release/Test.js", 
  • memUrl: "Release/Test.mem", 
To solve the problem you have, you just have to add gz to the end of those lines:
  • dataUrl: "Release/Test.datagz", 
  • codeUrl: "Release/Test.jsgz", 
  • memUrl: "Release/Test.memgz", 

If you upload the new version you should see that everything is working fine!

4 comments:

  1. Thank you so much for posting this!! Helped a lot! :-)

    ReplyDelete
  2. Interesting solution. Worked great for me.

    ReplyDelete
  3. Fantastic!! It worked!!! Such an easy solution ... but that takes a lot to find out!! Thanksssss so much :-)))

    ReplyDelete
  4. Wow, I have no idea what's going on there but it worked. For my project (maybe a later version of Unity?) I also had the line

    asmUrl: "Release/cat_quest.asm.js",

    which needed changing to

    asmUrl: "Release/cat_quest.asm.jsgz",

    Thanks so much for posting this solution!

    ReplyDelete