00:00
00:00
Newgrounds Background Image Theme

mariobros22 just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Browse Sections

  • Unity Resources

Newgrounds Wiki: Unity Resources

Basic troubleshooting


One of the main issues with WebGL games seems to be caused by the site loading the game in an iframe. If you're having problems and this page doesn't help you, first load the game with your browser's developer console open and check if there are any errors. Then, try searching for keywords related to the issue you're having + iframe (e.g. "unity3d webgl keyboard focus iframe") or search for any non-obvious errors you see in the console.


We will continue to add issues and any workarounds or fixes we find here. If you've done some search and still haven't resolved the issue you're having, feel free to post a question in the Unity3D WebGL Support thread.


Please be sure to do the above basic troubleshooting first!


How to publish your game on NG


The WebGL export option is how game developers publish Unity games to the web.


Unfortunately, this transition to WebGL has not been the easiest for many developers, and publishers like Newgrounds have had to make various changes to their server configurations to even support the way Unity has gone about implementing things.


Here is some introductory information on how to publish your WebGL unity games here on Newgrounds.


When you are ready, build your game. Make sure you are not doing a development build.


Once your game is built, you will have the following items in your folder, depending on your template.


Build <dir> | index.html (Minimal)

or

Build <dir> | TemplateData <dir> | index.html 


The Build folder contains all your core game files. TemplateData contains your basic loader and css assets, and index.html is the file that loads all these others into the browser.


Copy your files to a ZIP folder (make sure index.html is in the root ZIP folder) and upload it to your NG project.


You may be asking, why don't we use the .htaccess file and the Compressed folder. The short answer is security.


An .htaccess file essentially lets a directory override certain settings from the web server. In this case, it is used to tell your game to use the compressed version of your game instead of the release version. Unfortunately, we can not allow the general public to use .htaccess files because they could be used maliciously.


The good news is our servers will automatically compress your files when users load them. So if your release folder is actually around 100mb, the end user will only download 20mb or so.


Because you are putting your game in a zip file, your uploads will also be compressed, so you won't be waiting for 100+mb of data (unless your game is THAT huge compressed).


Including the .htaccess file and Compressed folder in your zip won't really hurt anything, but it will add the size of your compressed files to your upload and essentially double your wait time.


Common Problems


PlayerPrefs save data gets deleted when game is updated.

3p0ch has written a great guide on how to avoid this.


Keyboard events are not working


Try this workaround or this workaround if you're using jQuery.


Arrow keys cause the whole page to scroll


Try adding a simple javascript snippet to your index.html file:


<script type="text/javascript">


    // prevents key presses from bubbling out to the browser window


    var ignore_keycodes = [37,38,39,40];    


    window.addEventListener('keydown', function(e) {


        if (ignore_keycodes.indexOf(e.keyCode) > -1) {


            e.preventDefault();


        }


    });


</script>


Add this code anywhere inside of the <body> tag and you should be good to go.


You can add other key codes to the ignore_keycodes array as needed.


If you need to ignore the mouse wheel:


<script type="text/javascript">


    // prevents scroll wheel from bubbling up to browser window


    window.addEventListener('wheel', function(e) {


        e.preventDefault();


    });


</script>


You can use this same trick for pretty much any Javascript event.