Javascript for HTML5 development ?

Hi there I have a question about the big fuzz of IL2CPP and how unity is going to deploy to HTML5 using a tools that would convert C# to C++ and then to asm.js via emscripten.

Since the Unity Engine is made in C++, how hard would it be to simply compile the engine to asm.js and then to simply run game scripts made in javascript directly in the web browser ???

It must surely be easier to implement than the IL2CPP stuff and at least it would allow people that are only interested in web development to benefit from unity’s ease of use…

1 Like

There are a couple problems (a lot, actually) associated with porting anything to another platform and then there are even more when it comes to Unity. I’ll try to give a comprehensive list:

  1. One of the big problems with porting a large system to another language, are the differences between the new language and the previous one. C# is a “static” language while Javascript is a “dynamic” one. C# has OOP and Javascript has Prototypes. It’s not that one is better than the other, it’s that Javascript (as it is) does not allow you to express some of the language features the Unity engine relies on.
  2. Another big problem is the difference in environment. Unity runs on Mono and makes full use of .NET and/or the C++ stdlib. Javascript has it’s own equivalent “standard library”, but it completely differs from what the engine was built on.

Both of these mean that a “port” cannot really happen, as in: you couldn’t actually call it a port, simply because of the massive differences between the two environments. What would have to be done is a full rewrite of the entire engine, including a full redesign of the API and internal systems. At this point you might as well just make it an entirely different engine.

But lets say they somehow (magically) overcame these problems:

  1. Keeping multiple forks of very large projects up to date is virtually impossible. Lets go a bit over the top and say they “ported” the unity game engine to a different language for every platform. So: C# for windows, Objective-C for OSX/IOS, C for Linux, Javascript for the web and Java for Android. Then they found a bug. A big one. So then you have to go out and test if the bug is the same for every platform.
    Lets say you did that and you found the problem was the same on every platform. Now you have to go and fix it, for every single fork. And because all of the ports were written by different people and the inner workings aren’t all the same, you basically now have 30 people working a two to three man problem.
    But oh, there’s more. Lets say the problem wasn’t the same on every platform (which it never really is), now you have the most gigantic mess you’ve ever seen right in front of you: C# doesn’t do the right thing, Objective-C hangs, C segfaults, Javascript makes the browser crash and Java crashes android. Fixing one problem on one platform makes you find another on the others. Seeing the mistake they made, everyone at Unity gives up fixing the exponential amount of bugs that have just arisen and the company goes bankrupt. (Yes, again, overstatement)
  2. Using the same example, the huge amount of duplicate documentation that would have to be created is also part of the problem.
  3. Of course, the same goes for any kind of tests that happen for Unity.
  4. Everything anyone else has ever written for Unity, all the scripts on the wiki, all of these answers, would mostly be useless for the port. This would basically split the community between web-development and any other platform. I don’t think I have to tell you that this is not exactly the best thing for a community or the thing the community is about.

Now on to the Unity specific problems:

  1. The Unity editor is not a web browser. It can’t run Javascript. Sure, you could run a Javascript compiler for .NET, but then you’d still go through the same compilation process as with any other .NET language and the problem would remain. Either a completely new editor would have to be built for the browser, or you could never “hit the play button”.

All of this really boils down to one thing: Money. It’s not that Unity don’t want to give you a “port” of their engine in Javascript, it’s just that the amount of work, time and therefore money required would not make for a viable business. If you want to actually make your game in Javascript, use a game engine written for Javascript.