Advertisement

Is it inefficient to use Unity to turn 32kb of Javascript into a mobile app? Are there alternatives?

Started by August 21, 2016 08:30 AM
13 comments, last by Kylotan 8 years, 3 months ago

What is Unity actually doing? Is it simply wrapping a shell around the code, or compiling it into lower level code?

It possible to just make a simple app that is merely a browser, and run the js game code in that?

Part of the reason I ask is that my game code is <32kb and all I need is a menu and a way to connect to a server for PvP. The remainder will be all game trees, so a lot of recursion.

I tried a Unity built Minesweeper clone, which is a similarly simple, grid based puzzle. It took forever to load. The project has ~50x more objects than I have functions and is ~10,000x bigger.

Unity seems more like a graphics engine and mine is not a graphics-based game.

I personally don't like Unity, I find it time consuming and messy compared to other solutions but I know it has a lot of marketing behind it and many of my students do seem to like it.

Perhaps just be aware that Javascript in Unity (actually called Unityscript) and Javascript for web browsers are very different. So you might have to end up recoding quite a lot of your work if it is already standard Javascript.

You can make an app that just surrounds a web browser and run your game in that, it would work. I don't know what the components are called but you can pretty much just drag and drop it in using the visual designers.

Edit: What unity does for web exporting is convert its compiled .NET code (Unityscript/C# etc...) to C++ with il2cpp then it uses Mozilla's free and open-source transpiler to compile the c++ to very low level Javascript (asm.js). This is faster than normal javascript because it can be optimized well (although isnt very human friendly to develop with directly). The output binaries are very large because Unity, as an off the shelf product provides a lot of things even if you dont use them and doesn't strip out everything you dont need.

http://tinyurl.com/shewonyay - Thanks so much for those who voted on my GF's Competition Cosplay Entry for Cosplayzine. She won! I owe you all beers :)

Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.
Advertisement

Thank you Karsten!!! Nearly everything Unity offers, I don't need. But because it is a game, the pat answer has been "use Unity." (I ran into a similar problem when I first developed the code. When I'd hit a bump with a simple function, the standard answer was "use a library". It turned out that everything I needed to do could be accomplished in pure JS.

Followup Question: Is using a massive library for a single function also inefficient? (I suspect it's a different process than what's going in with Unity.)

If you are using pure JS, you can use cocos2d-js library or Phaser. You can use three.js for 3D. Wrap them with Crosswalk so it focuses on Chromium browser engine and not worry much on device differences (except for WebGL device-level features). That should give only what you need and definitely lower the file size and initial loading time.

Actually there are plentiful JavaScript game engines and libraries for both 2D and 3D. Here is a short incomplete list of some popular ones: HTML 5 Game Engines. Unity is targeted towards .NET developers and more suitable for PC/Console/Mobile games. While it can do browser games, I believe it is an overkill in most cases.

all I need is a menu and a way to connect to a server for PvP.

Why do you think Unity will do these things for you, and why can't you do them in Javascript?
Advertisement

Followup Question: Is using a massive library for a single function also inefficient? (I suspect it's a different process than what's going in with Unity.)

Personally I feel that dragging in a library just for a single function is a bad decision overall. It is not elegant and often causes problems with maintanance later on.

However... I must be wrong on this because I see so many Javascript developers drag in all sorts of crazy dependencies for doing extremely simple tasks. I am sure you have already seen the word "JQuery" pop up many many times on help forums. Always, without fail just to split a string, some weirdo will suggest JQuery.

But that said, I am in the fortunate position of being able to avoid working with developers such as these ;)

Edit:

It reminds me of the time when someone dragged in the GLM maths library into our database project just to use the vec3 length function. The compiler we had on our build server didn't support such an old version of GLM and so when it came out why he had done this, It certainly didn't inspire much confidence in any of his later decisions. I think he later went on to use glm again, just for glm::detail::tvec1<T> or something just to zero initialize member variables... I did chuckle ;)

http://tinyurl.com/shewonyay - Thanks so much for those who voted on my GF's Competition Cosplay Entry for Cosplayzine. She won! I owe you all beers :)

Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.

Personally I feel that dragging in a library just for a single function is a bad decision overall. It is not elegant and often causes problems with maintanance later on.

However... I must be wrong on this because I see so many Javascript developers drag in all sorts of crazy dependencies for doing extremely simple tasks. I am sure you have already seen the word "JQuery" pop up many many times on help forums.


Hey, JQuery is usually a good choice, because it provides you with a lot of functionality that you're probably going to use later. It's a bit like seeing someone struggle with text manipulation using char*, and telling them to use std::string instead. They may not really need everything that std::string provides, but you may as well have it.

But Javascript developers do far worse things than that - you may have heard of the left-pad incident where someone removed a trivial library from the NPM package manager, one that adds a few spaces to the left side of a string to make it up to a certain length, and tons of important software was immediately broken because they depended on it indirectly.

However, this is not really an argument against using 3rd party libraries - it's an argument against:

  • deploying software by relying on every user having access to collaborative package managers
  • installing packages by name and expecting them to never be revoked, replaced, or moved
  • hiding a dependency's dependencies from the user
  • making your standard libraries so anaemic that you can't do much without pulling in 3rd party code or reinventing your own wheels
  • etc.

If a library does what you want, has already been tried and tested, and doesn't harm you or your users in some way (e.g. increased download times, difficulty of maintenance, security risks), then it's almost always more sensible to use it than to roll your own alternative.

They may not really need everything that std::string provides, but you may as well have it.

Hmm, its closer to pointing people towards Qt, just to use QString to concatinate two char* together ;)

But yes, I see your point but I still do see too many Javascript developers dragging in JQuery for very trivial things.

http://tinyurl.com/shewonyay - Thanks so much for those who voted on my GF's Competition Cosplay Entry for Cosplayzine. She won! I owe you all beers :)

Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.

They may not really need everything that std::string provides, but you may as well have it.

Hmm, its closer to pointing people towards Qt, just to use QString to concatinate two char* together ;)

But yes, I see your point but I still do see too many Javascript developers dragging in JQuery for very trivial things.

I see the opposite. Most JavaScript developers I know treat JQuery as though it is part of JavaScript. Some of the newer developers have never programmed JavaScript without it and most new introductory Javascript textbooks start with right from the beginning the main reason being that to access the DOM in a consistent way across multiple browsers requires a lot of boilerplate code.

This topic is closed to new replies.

Advertisement