The Death of Unity Web Player

Getting Started With WebGL

Posted by Aaron Salisbury on August 23, 2015

Upon exhaustive research and evaluating my goals, I decided that Unity would be the engine in my self-driven mission to develop games. I already work with C# professionally and with Unity's renown Web Player I could have my test concepts online and playable immediately. Oops ... Google, with others following suit, just abandoned support of all NPAPI plugins. Some argue whether this was worthwhile (I think it is) and consider workarounds. Instead, I think we had ought to embrace, as Unity has, WebGL. They are putting the resources behind it, even bringing in engineers from Mozilla, and the last I looked, they have it running at only ~1.5 times slower than native code. All the major browsers are expected to support WebGL and now end users will not have to be bothered with having to download a plugin. That said, WebGL builds are now available with Unity 5, but as an early-access and with some limitations.

Currently Unsupported

  • MovieTextures
  • Runtime generation of Substance textures
  • Networking other then WWW class (a WebSockets plug-in is available)
  • Support for WebCam and Microphone access
  • Hardware cursor support
  • Most of the non-basic audio features
  • Script debugging
  • Threads
  • Any .NET features requiring dynamic code generation

Getting Started

Getting started is as easy as beginning any build. Simply go to File > Build Settings, and select WebGL. Don't forget to select "Switch Platform".

Unity Build Settings

While in the build settings, you could continue into the player settings in order to select a template for how your game will appear when launched in the browser. Custom templates are added to a project by creating a folder called "WebGLTemplates" in the Assets folder and the templates themselves are subfolders within this folder. I recommend copying the default template here and renaming it. Then you can make your changes incrementaly. For me, the default instalation location was: C:\ProgramFiles\Unity\Editor\Data\PlaybackEngines\webglsupport\BuildTools\WebGLTemplates

Let's Play

So go ahead and develop your alpha to the point you're ready for a live test. This is where I ran into the most frustrating issues of all. The first, if your not launching from your site's root location as I imagine is most people, you need to help point to your project files. To do this, edit the httaccess file that gets generated for you during the build process. Add this line:

httaccess

Include however many nested folders down to your game folder that you chose to build to. "game-folder" will instead be the name of your game.

The next problem is more involved and was difficult for me to research. There seems to be a bug with how a couple files get named as well as referenced in JavaScript. I've been expecting this to be patched, but so far it hasn't over the last few Unity updates. Navigate to your game folder and step into the Release folder. The file in error has "html" injected into the middle of it and will look like "Your_Game_Name.html.mem". Just remove the superfluous .html, including the dot. The JavaScript file that is also named after your game needs to be edited next. I recommend right clicking on it and selecting edit, due to the size, trying to launch the file in a code editor can take some time. Do a CTRL+F search for the original file name that you had just changed, including the .html.mem extensions. There should only be one instance, go ahead and delete the .html like before. Finally step out of Release and into Compressed. Repeat the renaming steps above on these compressed versions. If all is done correctly to this point, your game should launch without further issue.

Click HERE to check out a live example.

I hope that I've helped some people and if you are considering a WebGL build, I highly recommend perusing the following:

On the Future of Web Publishing in Unity and WebGL Roadmap