Version: 5.4 (switch to 5.3)
WebGL Player Settings
WebGL Browser Compatibility

Getting Started with WebGL Development

What is Unity WebGL?

The WebGL build option allows Unity to publish content as JavaScript programs which use HTML5 technologies and the WebGL rendering API to run Unity content in a web browser. To build and test your content for WebGL, just choose the WebGL build target in the Build Player window, and hit Build & Run.

Technical overview

To run in WebGL, all our code needs to be JavaScript. We use the emscripten compiler toolchain to cross-compile the Unity runtime code (written in C and C++) into asm.js JavaScript. asm.js is a very optimizable subset of JavaScript which allows JavaScript engines to AOT-compile asm.js code into very performant native code.

To convert the .NET game code (your C# and UnityScript scripts) into JavaScript, we use a technology which we call IL2CPP. IL2CPP takes .NET bytecode and converts it to corresponding C++ source files, which we then compile using emscripten to get your scripts converted to JavaScript. This conversion process might run into some compatibility issues with your script code in the early-access release, which we will work on resolving, but as long as you don’t require threads or dynamic code generation features it is expected to work.

Platform support

Unity WebGL content is supported in the current versions of most major browsers on the desktop, however there are differences in the level of support offered by the different browsers. Mobile devices are currently not supported by Unity WebGL.

Not all features of Unity are available in WebGL builds, mostly due to constraints of the platform. Specifically:

  • Threads are not yet supported due to lack of threading supporting in JavaScript. This applies to both Unity’s internal use of threads to speed up performance, and to the use of threads in script code and managed dlls (Basically, anything in the System.Threading namespace is not supported).

  • WebGL builds cannot be debugged in MonoDevelop or Visual Studio. See: Debugging and trouble shooting WebGL builds.

  • Browsers will not allow direct access to IP sockets for networking due to security concerns. See: WebGL Networking.

  • The WebGL graphics API is equivalent to OpenGL ES 2.0, which has some limitations. See: WebGL Graphics.

  • WebGL builds use a custom backend for Audio, based on the Web Audio API. This supports only basic audio functionality. See: Using Audio in WebGL.

  • WebGL is an AOT platform, so it does not allow dynamic generation of code using System.Reflection.Emit. This is the same on all other IL2CPP platforms, iOS, and most consoles.

WebGL Player Settings
WebGL Browser Compatibility