Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question WebGL vs Desktop, Unity vs js engine

Discussion in 'Web' started by andyz, Oct 30, 2023.

  1. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,224
    Hi I need to compile the downsides of Unity WebGL (the upsides are build once, use anywhere, but only when it becomes lightweight and performant on all platforms - not sure we there yet! "Unity WebGL doesn’t support mobile devices")

    1. Unity WebGL vs Unity Desktop/native - e.g. lower CPU performance, less memory on web? What are the memory limits? How does the performance suffer and why and to to what degree on CPU (WebAssembly vs il2cpp)?

    2. Considerations for using Unity webgl vs say PlayCanvas (straight .js) - which I assume comes down to better performance from Unity at cost of higher memory, poor mobile support, less easy to fully integrate with web-page around it?
     
    Last edited: Oct 30, 2023
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,028
    1. Far too broad. You cannot compare WebGL with any other platform, it is severely restricted all around.
    2. The #1 feature for using Unity is tooling, with the tradeoff of generally more resource usage (specifically initial load time). JS engine tools are pretty much crap, although to be honest I haven't followed them in the past 3 years.

    It really depends on what you intend to do. If all you need is an orbit camera around a product mesh and some text, you will be doing well with any JS engine due to superior loading time and be able to hack everything together in code. But as soon as you need more complex GUI, more scenes, more assets, more animations, more scripting, more effects, more postprocessing, or more whatever then you are pretty much only trading a few seconds of startup time and a little more memory for far superior tooling and workflow.

    WebGL on mobile, and in particular iOS, is pretty much crapware and bad UX and long loading times and frequent crashes and so on. If you have the above single product orbit camera, great, you can do that.

    But if you intend to build something closer to an action game, WebGL just sucks on mobile. You are FAR better off making a native app, even if you already have a WebGL version of your game on desktop. Of course it won't hurt to see how far you can take your project on mobile (specifically iOS) in WebGL you should be prepared for ditching that in favor of native apps.

    Keep in mind that WebGL is NOT a single platform! Your WebGL app runs on Chrome, Firefox, Edge, Safari, multiplied by the number of operating systems (Windows, Mac, Linux, iOS, Android, etc) all of which may exhibit varying degrees of feature support and issues, and each requires at least basic compatibility testing for EVERY release! Expect to go bughunting the odd issue that only occurs on one OS and one browser and possibly only on a range of devices.
     
    andyz and Ryiah like this.
  3. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,224
    1. I meant to say Unity WebGL vs Unity native (corrected) - I tried it in the past and memory was too limited and no mobile and sometimes the lesser GPU was selected on a dual GPU system (!!) - but things have probably changed since... or not.

    2. I totally agree with tooling and the fact you have C#, but truth is I want to persuade other people who are not Unity devs

    I am looking at heavy apps/games not simple scenes, even heavy UI.
    The web is great for UI, it is great for lightweight graphics, I don't think it is good for complex and powerful apps and yet engines like PlayCanvas (which is rather too close to Unity in design) and CAD apps like Sketchup running in a web page suggest quite a lot can be done (though I am not blown away by any graphics there).
     
  4. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,409
    memory is limited, but, it has mulit threading, and some stuff runs on mobile - but not everything..
     
    andyz likes this.
  5. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,711
    WebGL's biggest limitation in my opinion is that it's not just one platform but rather many platforms: one for each of the major browser manufacturers (two if you count the mobile versions).
     
    Last edited: Oct 30, 2023
    MadeFromPolygons, andyz and CodeSmile like this.
  6. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,028
    I checked out PlayCanvas real quick, at least what I see on the website it seems to have come a long way in terms of tooling. But first sights are often misleading.

    Question is, which you have not indulged in: why do you need to persuade other people? Who are they? (devs vs biz?) What is the project? What is the actual decision to be made? (Unity vs PlayCanvas? WebGL vs Native App?)

    A couple years ago the business case for using Unity to make a complex configurator was a rather straightforward decision. These days I‘d surely have to take a close look again, and it really depends on the project and people involved.
     
  7. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    432
    In case you're interested, Unity has a blog about it
    https://blog.unity.com/technology/benchmarking-unity-performance-in-webgl

    I would say it's not fair for Unity, as Unity is a modern engine that has implemented lots of optimization based on Multi-Threading and SIMD while WebGL doesn't support them. If people want to make games for WebGL only and the game itself is performance-sensitive, they probably should switch to another engine instead. But if WebGL is just one of the platforms, then Unity might be the best choice.

    Last, believe it or not, Unity and Unreal are still the best engines the public can get, way better than other competitors.
     
  8. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,028
    @zhuchun The article you linked is almost 10 years old! ;)

    WebGL was a completely different tech stack back then. Unity has since switched to WebAssembly, Browsers have evolved their WebGL implementations and WebGL v2 has now largely deprecated v1.
     
  9. ferretnt

    ferretnt

    Joined:
    Apr 10, 2012
    Posts:
    408
    Unity WebGL remains fairly crippled because the browser is still crippled. You're not going to be able to load something modern like 6Gb of assets on Unity WebGL, but you won't be able to on any other browser-based engine because the browser itself is limited to 4Gb (side note, I can't wait for Unity to be 4Gb rather than 2Gb.)

    Some other browser based engines will let you achieve results that were visually impressive on standalone 10 years ago with less hassle and faster iteration than Unity because they aren't built on a massive C#/C++ --> EmScriptem --> Wasm stack.

    There isn't a platform that supports modern game development in a browser, because browsers are still single threaded 32 bit non-simd processes with rudimentary GPU support. If that's good enough to do what you need, great.
     
  10. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,028
    Browsers are not crippled, they are just far more concerned about security, compatibility and stability over game performance or rendering features.

    WebGPU may eventually provide us with faster, more vibrant rendering but realtime 3D on the Web will always lag behind every other platform, including low-end mobile devices specifically because WebGL content needs to be able to run on said low-end mobile devices too.

    We will probably not ever see cases where a WebGL game would be device-specific, such as "You are running this on an iPhone XXXVIII but the minimum requirement is an iPhone XLIV".

    They are 64-bit processes and with WebAssembly you can definitely write your own multithreaded SIMD code, so you can assume that's also being utilized internally.
     
  11. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,224
    This is not quite accurate. WebGL2 based on OpenGL ES 3.0 GPU support means you can get very good GPU support. The main issues are on cpu (js single threaded) and memory side afaik.

    Wasm seems initially a heavyweight hack and mainly used for complex pre-coded systems like Unity and for example Sketchup (free version), but you can mix js and wasm - some minor parts of PlayCanvas are actually wasm (physics I think).
     
  12. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    432
    That's true, however, my first-person experience is somewhat different.;)

    I'm developing a WebGL game on WeChat, they call it a "mini program". Tencent has a project (https://github.com/wechat-miniprogram/minigame-unity-webgl-transform) that help Unity devs to port their WebGL builds into the format WeChat needs. That repo has been well documented(not sure if the English doc is also available).

    They've stated that:

    1. WebGL2 support is not guaranteed, by the end of 2022, only 85% Android and 75% iOS devices on WeChat can support it. So when serving ads, not-supported users should be filtered out.
    (https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/blob/main/Design/WebGL2.md)

    2. Unity WebGL is based on WASM + WebGL...
    ...Unity WebGL doesn't support multi-threading so related optimization for AI/Animation/Rendering is not available...
    ...In general, a native app is about 3 times faster than a Unity WebGL build, thus devs should take care of the CPU end bottleneck...
    ...GPU Instancing and SRP batcher require WebGL2...
    ...WASM is about 1.5 times faster than JS in theory, However, Unity is not well optimized for browsers, so JS is somehow lighter than Unity in many cases...
    (https://github.com/wechat-miniprogr...m/blob/main/Design/OptimizationPerformence.md)

    I would consider Unity WebGL as a thing that's for everyone, including people using pretty low-end devices. Neither Unity nor WebGL are good choices for performance-sensitive games unless WebGL2 and WebGPU are well-accepted by most devices, I mean, maybe more than 95%. I know that may sound like a big number, but it also means that we still need to give up 5% of players, that's a lot. Real-life story, in a past game of mine, the whole company made a huge determination before giving up ~2% of players in one of its major updates.
     
    Last edited: Nov 2, 2023
    MadeFromPolygons and Marks4 like this.