• Register

Endurance is an old school dungeon crawler with rogue like elements.

Post news Report RSS Diary 2: Web Builds for Indie Games

One of the reasons I’m using Unity3d to build my game is that it makes it really easy to build to different targets. Unity supports windows, mac, Linux, most of the consoles, and last but not least web players. The fact that a full on game can be run in a modern web browser is quite amazing. While I intend for the final release of the game to be stand alone, it’s very helpful to be able to publish web builds as it gives people an easy way to try out your game.

Posted by on

Diary 2: Web builds for indie games

A little warning, this diary entry will get a little technical :)

One of the reasons I’m using Unity3d to build my game is that it makes it really easy to build to different targets. Unity supports windows, mac, Linux, most of the consoles, and last but not least web players.

The fact that a full on game can be run in a modern web browser is quite amazing. While I intend for the final release of the game to be stand alone, it’s very helpful to be able to publish web builds as it gives people an easy way to try out your game.

Unity Plugin vs WebGL

Right now Unity has two different approaches to building for web players. The first is the Unity Plugin. This has been around for ages. It’s great. It’s small, fast, and works on most things. It however has one major drawback. It’s no longer supported on Chrome and may be dropped from other web browsers in the future too.

This is because the Unity Web player uses an old native plugin API NPAPI (from Netscape all those years ago). The NPAPI gives a plugin nearly full control of the systems resources, which is great for performance, but terrible for security. Google and others are taking steps to phase out this 22 year old API in order to clean up their browsers and remove potential security risks.

This is where WebGL comes in. WebGL is Unity’s answer to this depreciating API. The idea is to build an application using only the standard tools available in modern browsers. JavaScript and WebGL. By doing this a program can run natively in any HTML5 browser and doesn’t require any plugins to run at all. How Unity accomplishes this is quite staggering.

Ok… so here is where it gets technical.

How does Unity convert a game to JavaScript? It does it like this. First it takes your code (in my case around 20,000 lines of C#). The it compiles it into .net byte code. Next it converts this byte code into C++ code using a feature called IL2CPP. (unity had to develop technology to do this. You can read more about it here) Then the C++ code is compiled into a special form of JavaScript called asm.js. Finally, that JavaScript is run on your browser, and if your using Firefox, compiled into native code.

It’s quite a process, from c#, to byte code, to C++, to JavaScript, and then finally to native instructions.

Let’s look at the pros and cons of doing this.

The good

  • You end up with a game that should run almost anywhere.
  • The user doesn’t need to install anything to run your game.
  • The end produce is JavaScript which is continually being worked on and is getting faster every week.

The bad

  • Having such a lengthy build chain means slow compile times.
  • The performance for JavaScript still isn’t great.
  • The JavaScript format greatly increases the file size.

Impact on Endurance

Because the Alpha builds of Endurance are built with the Web player plugin, some people are not able to run it. I spent most of today testing Endurance with the new WebGL to get a feel for how it would work. Here is what I found.

Performance:

With most of the debugging disabled I get about 1/7th the speed using WebGL as I do running natively. Even so, I still hit 60fps in the dungeon on my development machine.

Comparison

File Size:

This is the real killer. The WebGL version of the game weighs in at 205Mb! This compares to the Web player plugin version which is just 35megs.

Unity will soon support compressing their WebGL applications which will bring the size down to around 100Mb for me, and potentially more like 70Mb once I remove some of the debugging information.

Quality:

When doing my testing I noticed the lighting in the WebGL build is quite different from that in the other builds. See below.

I spent quite a bit of time trying to work out what is happening here. All I can gather is that in the WebGL build all my materials change their smoothness property from what I have it set to, to a default (very high) value.

Conclusion

The great thing about Unity is being able to push your game out to another platform with just the click of a few buttons. The WebGL platform is still a work in progress, but as it stands today an almost 6x increase in size, 7x speed drop, and slightly broken lighting means I’ll have to wait a little longer before I make the switch.

That being said. The WebGL platform is getting better and better, and I’m very glad it’s there, but for now it’s the Unity Plugin for me.

Today’s Changes [0.11.6]

  • Tested the WebGL platform.
  • Fixed some issues with lighting and doors.
  • Stopped “new record” notifications when creating new characters.
  • You can now use the arrow keys to move (as well as WASD)
  • Various bug fixes and tweaks.

Endurance now sits on a few sights, mine, IndieDB, and itch.io.
Most of these I’ll just be updating for major releases, however the most up-to-date version can always be previewed from my website here

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: