top | item 16567893

Ask HN: Is it possible to use Unity on the web in 2018?

8 points| nicc | 8 years ago | reply

We're trying to load a Unity "hello world" example into a webpage, but the WebGL player gets stuck for 4 seconds before showing the "Unity" splash image.

We are testing with a 2D picure of a lama. Why would it get stuck?

I can't stop myself from thinking that WebGL is being purposily boycotted by Apple and Google, because I have a powerful phone that does very complicated and CPU-intensive stuff and I can't believe it struggles with a picture.

This is the URL: http://countryfortress.com/LamaExampleWebAssembly/

10 comments

order
[+] jonasechterhoff|8 years ago|reply
A few comments (Disclaimer: I work at Unity): -As others said, with Unity, you get a full game engine cross compiled to JavaScript/WASM, which has more overhead then simply rendering an image by other means (like img tag). -We don't officially support mobiles for the Unity WebGL build target, because we believe that the platform (browsers and hardware) is not yet ready for this use case (running a full game engine compiled to the web) yet. That said, you might get better results with simpler engines which do support mobiles. -WASM support on iOS is currently broken, so this probably would not work regardless of engine used: https://bugs.webkit.org/show_bug.cgi?id=181781#c4 (Try making a JavaScript release build instead)
[+] nkkollaw|8 years ago|reply
Well, first of all it's so awesome to get a reply from someone who actually works there! :-)

I understand what you're saying. Of course, we're aware of the overhead compared to just including an image with a HTML tag, it was just a test to see if we could make the thing work with the minimum amount of complexity possible.

For us, it's not important to support mobile browsers: the latest desktop browsers would suffice. However, we can't build for the web without a 10-second delay before the image is shown.

What we're looking to achieve is to use Unity for native games as well as very simple animations for the web (a 2D landscape with parallax, at the moment), so that we have only 1 editor, and 1 technology to learn.

I'm also not the person who will actually build the product, I'm just helping out with research and I'm not extremely familiar with WASM and similar. What is a JavaScript release build? Is that a way of exporting the project that would allow us to eliminate that 10-second delay?

[+] Kiwikwi|8 years ago|reply
TL;DR: To deploy on mobile, you should compile your Unity project as an app.

Per the manual: "Mobile devices are not supported by Unity WebGL." (https://docs.unity3d.com/Manual/webgl-gettingstarted.html)

You're not just rendering a picture, you're running a full-fledged high-end game engine, in JavaScript (meaning a ~50% slowdown), and using that to render a picture. It is to be expected that even high-end phones will struggle with that.

Unity WebGL is intended to be used as a frictionless way of distributing games to desktop users (think sites like Kongregate). On mobile, the respective app stores arguably already provides a similarly frictionless distribution option... so just build your project as an app.

Alternatively, you can look into lightweight engines that specifically target WebGL. These will usually run just fine on mobile, though they obviously don't offer the same feature set as Unity.

[+] nkkollaw|8 years ago|reply
Sorry, it seemed from my comment that we care about mobile, but we'd be happy if this worked on the desktop.

I'm wondering if we can optimize the full-fledged high-end game engine so that some components that are not used are not loaded.

[+] Dryken|8 years ago|reply
if you used a "WebGL 1st" engine it would probably work. Unity is "compiling" it's project for WebGl so that's one big process that can easily break.
[+] nkkollaw|8 years ago|reply
Yes we don't understand. We're also exporting with WebAssemly support instead of AMS. The thing loads fine, then gets stuck: http://countryfortress.com/LamaExampleWebAssembly/.

By "webgl-first" you mean three.js or D3? We use Unity for iOS and Android, and we were looking to use a single tool for everything (if possible, of course). Is there any way to turn a simple Unity project into something that won't bring the browser to its knees?