So many WebGL issues... Is there a stable Unity version? Every version introduces a new bug

I started developing a game on a Unity LTS version 2020-ish and later decided to port it over to WebGL but that was such a drama, in the end I managed to make it playable by sacrificing the game’s audio. But man the things I had to do to get to that point. What I dislike about Unity is that there are very weird bugs that popup upon a new version release whose code probably wasn’t even touched for that new release to begin with.

Before the drama started I ofcourse had to fix mandatory things like capping the fps amount, fixing all the memory issues, changing the websocket solution so it doesnt use native sockets, eliminating any dotnet library usage cause the browser doesn’t support it (I was using an old version of newtonsoft’s JSON solution and now I use JSON.NET the newer version), letting exceptions go through so the browser doesn’t crash for testing purposes. Those are understandable issues, but…

First I had an issue where the game’s audio wasn’t working (Unity Issue Tracker - [WebGL] Audio is not played when in built Player) apparently I could fix that by updating my version to 2021.1.x (which is a beta version). Yes, that fixed the audio, but not entirely, for some reason the audio plays only a couple times until it just gives up and it also just entirely stops working if you switch tabs.

Now that wasn’t a big deal, but the next issue that popped up blew my mind. For some reason that exact version’s UnityWebRequest.downloadhandler.data always returned null. Literally only that property of downloadhandler suddenly always returned null, I double checked, triple checked, debugged everything and I simply could not find the culprit thinking I made a mistake, turns out it’s a known unity issue Unity Issue Tracker - UnityWebRequest downloadHandler.data is null after downloading a texture using UnityWebRequestTexture.GetTexture() Note how it says fixed in ‘‘2022’’. Now this was a huge gamebreaking issue for me because my 2d game downloads a lot of textures from the internet and it needs to cache it for future use, I make use of the bytearray it returns from the downloaded texture.

So anyway I downgrade my version to a version that doesn’t have this issue, I decided to stick with an LTS version because I thought that would be a reliable version, nope, I downgraded and suddenly this issue arised = Unity Issue Tracker - [WebGL] Mouse events are not called on builds when the scene does not have Event System object

Bonus: I have to set exceptions to None so my webgl build will run faster and take up less space, turns out you can’t do that with a couple unity versions, which is another bug = How do I DISABLE_EXCEPTION_CATCHING = 1 for webgl?

After this, the only unity version I have found that doesn’t have gamebreaking issues is the one that has no webgl audio working, so compromises had to be made and I stuck with version 2020.2.0f1
Now the biggest issue that is left - and it seems Unity doesn’t want to fix - = Mobile touch input in input fields for webgl Unity Issue Tracker - Mobile virtual keyboard does not pop up when Input field is tapped inside mobile device browser

Question #1. Will Unity make Webgl work with mobile’s input field? If yes, when?
Question #2. Is there a unity version that eliminates all the bugs I described, including the webgl audio?

At this point I should just rewrite the front end of my game in React, which will also use less CPU and Memory. Is there a secret plan of ditching WebGL and Unity doesn’t want to tell us and that is the reason why their support for WebGL is so lacking? Porting a Unity game made to browser is only possible through WebGL as far as I know without rewriting the entire game, it enables a developer to target a bigger audience. Especially for iOS/mac users because I only have PC and Android builds and no Mac builds.

5 Likes

WebGL was the starved child of Unity for a -long- time. On the good news front, I would argue that there has been more improvements, fixes and major updates in the last 12 months than in the 5 years (2015-2020) following the NPAPI plugin depreciation. Talking on a regular basis with Unity’s employees, I can confirm they have done a big shift towards WebGL lately with new hires and added a new team of engineers dedicated on improving the WebGL experience. Unfortunately, this has only happened in the last ~6 months, so things are just now slowly ramping up.

As for your questions, not full answers but partial:

  1. Mobile is -not- officially supported by Unity WebGL at this point. But it is a work-in-progress on the roadmap with major first steps being added in the 2021.2 beta. Unfortunately, that version is still borked at this point for WebGL… but I don’t have much expectations for a beta anyhow.

  2. As fixes get backported to LTS releases, this is a though question to answer. I had more success with the 2021.1 version than the previous LTS ones. But due to the massive changes done in 2021.2, I also expect it to be somewhat of a ‘breaking’ release. With a lot of the time-consuming fixes staying on that version in the future. Not ideal, I know.

All in all, I absolutely feel your pain. It’s very difficult to ship a production ready project with Unity WebGL without going through many hoops and loops. I would still encourage you to keep posting here as I know the Unity devs are taking those posts very seriously and are active on those forums, especially compared to other forums out there.

Cheers and good luck!

5 Likes

All of your concerns are understandable and these instabilities that come up with new versions are a concern for us, too. The bug reports are very helpful and much appreciated.

https://issuetracker.unity3d.com/issues/audio-no-longer-plays-in-build can be back-ported. I’ll open a ticket to get that done. I’m not aware of an issue of the audio “giving up”, that sounds like a separate issue.

https://issuetracker.unity3d.com/is…e-using-unitywebrequesttexture-dot-gettexture says it’s fixed in 2021.2. It looks like it was a bug from the scripting team, I’ll ask if it can get backported.

https://issuetracker.unity3d.com/is…n-the-scene-does-not-have-event-system-object was fixed by IL2CPP in 2020.1.

The exception bug was a result of the new Emscripten, and that has been fixed and is in the merge queue.

As for https://issuetracker.unity3d.com/is…-field-is-tapped-inside-mobile-device-browser, Unity does very much want to do this, because it’s something we’re working on now. It’s less trivial than you might expect, to be robust, due to mobile browser requirements and Unity events, but it will come.

Question #1: Yes, working on it. Sorry, can’t give an estimate, lots of time variables before delivery.
Question #2: No, but most of fixes should be backport-able so I’ll put in the requests.

3 Likes

Thank you for the reply.

My competitor is already winning the market by making his game in React instead and enabling iOS users to play it like that, so please make webgl mobile a top priority

4 Likes

You know, I feel you about all your concerns. But, javascript browser games aren’t “winning the market.”

We are here for the glory sir. stuffing as much 3d crap with particles, lighting, reflections, cinematics, vfx, customizations, media sharing as possible is what we are here for. Nobody else pushes browsers harder than we do here.

Safari is mainly busting our balls here, forcing us to use webgl 1.0, and being garbage for the past 10yrs.

I am also struggling with Unity 3D WEBGL builds.
It is the most unstable toolchain I’ve used in the last ten years.
There is a good article about it here:

As far as I understand, it is:
Unity 3D (C#) → CPP/C → add https://www.libsdl.org/https://emscripten.org/ → link with bee → output https://webassembly.org/
Five stages, five sources of warnings/errors/bugs.

Now an empty 2023.3.4f1 WebGL project fails with an incomprehensible linking error:
Building Library\Bee\artifacts\WebGL\GameAssembly\release_WebGL_wasm\un71z5llu0b0.o failed with output:
emcc: error: '“C:/Program Files/Unity/Hub/Editor/2022.3.4f1/Editor/Data/PlaybackEngines/WebGLSupport/BuildTools/Emscripten/llvm\clang++.exe” -target wasm32-unknown-emscripten -DEMSCRIPTEN -D__EMSCRIPTEN_major__=3 -D__EMSCRIPTEN_minor__=1 -D__EMSCRIPTEN_tiny__=8 -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-cxx-exceptions -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -Werror=implicit-function-declaration -Xclang -iwithsysroot/include/SDL “–sysroot=C:\Program Files\Unity\Hub\Editor\2022.3.4f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten\cache\sysroot” …

After like 15-20 hours of struggle I am in despair:
Is there a stable Unity 3D version, that can build WebGL with Textmesh Pro ?

I now run the …\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\python\python.exe as administrator, this way Unity can build.
Took me like 25 hours to get over this bug.

1 Like

@zbalai yes, it takes a lot of work to make Unity games run on the web :slight_smile: converting an entire engine made with C++ and scripts written in C# to something that a browser understands requires many stages, just like you listed.

Now when it comes to the issue you listed:

  1. I assume you meant 2022.3.4f1 instead of 2023.3.4f1?
  2. I want to reproduce the issue you encountered, can you confirm this information about your setup: From the logs I see you’re using a Windows machine? did you happen to try this on a Mac? also: I’m going to try this with an empty project with TMPro installed, if there’s anything else I’m missing let me know :slight_smile:

If TMP is the problem…
This is almost certainly something to do with the zeroing Canvas bugs in 2022.3.2 and up.
https://discussions.unity.com/t/921651

This is one of the problems, but there are many, not least of which is a conflict between the New Material Variants and TMP’s idea of Material Presets.

There’s another with TMP objects disappearing in 2022.LTS (all versions) that has nothing to do with the Canvas bug.

@zbalai I just created a new 3D project with the TextMeshPro package installed on both my 2019 MacBook Pro and on my Windows machine and both built quickly. Can you attach the project that exhibited this behavior?

For what it’s worth, we really are doing our best to make this platform as stable and bug-free as possible. We’ve also done a lot of work on our testing framework recently, and have been triaging bugs almost daily. We rely on (and appreciate) your bug reports very much because they are the fastest way for us to get our investigations going.

2 Likes

I can’t talk in the name of anyone else but I know I appreciate the recent uptick in community interaction on the forums recently, especially by you @unityruba . Reminds me a bit of the good old days when @jukka_j was here daily.

All that to say thank you for you and your teams efforts on improving and maintaining this crucial platform.

2 Likes

Hi @unityruba
Thank you for your care!
Yes I meant 2022.3.4f1.
I am using windows 10.
I just started a new project with no changes whatsoever.
It didn’t build WEBGL first, but then I turned off GZIP compression and then it went through.
Now the funny part: I turned on GZIP again and now it builds with it on too.
Maybe I would start with meaningful error messages, not like “BUILD FAILED … CPP” and then 30 stack trace lines.

@zbalai so is it building successfully now?

Hi Unityruba

Thanks for your care!
I’ve just downloaded a 2022.3.6f1 and tried to build an empty WebGL project.
It brought these - for me at least - uninformative error messages:
9190826--1280900--upload_2023-8-3_10-12-6.png

Building Library\Bee\artifacts\WebGL\build\debug_WebGL_wasm\build.js failed with output:
emcc: error: ‘“C:/Program Files/Unity/Hub/Editor/2022.3.6f1/Editor/Data/PlaybackEngines/WebGLSupport/BuildTools/Emscripten/binaryen\bin\wasm-opt” --strip-dwarf --post-emscripten -O2 --low-memory-unused --zero-filled-memory --strip-debug --strip-producers Library/Bee/artifacts/WebGL/build/debug_WebGL_wasm/build.wasm -o Library/Bee/artifacts/WebGL/build/debug_WebGL_wasm/build.wasm --mvp-features’ failed (returned 3221225477)

Tried turning off GZIP, didn’t work this time.

Then tried running python.exe (and similar build tools like bee) as admin, it works now.
9190826--1280906--upload_2023-8-3_10-19-53.png

Maybe it is only my computer? Later I will try switching to Windows 11, maybe we will have more luck there.

Dear UnityRuba and fellow struggling developers

I’ve spend like 80-100 hours solving this problem.
Finally I’ve found the real source:

THE MAINBOARD (hardware)

Actually all kinds of stress was handled by the mainboard, I could use all kinds of software like Blender and Photoshop for weeks and months.
Everything run well EXCEPT UNITY 3D WEBGL compilation!

So sorry for the anger and unnecessary posts!
Interestingly authorization change sometimes solved the problem, I don’t know why.

This doesn’t mean that these error messages are always caused by a hardware issue, but in my case it was like this.
It seems the WEBGL compilation process ( WebGLSupport folder in the Editor has 1400 folders and 12374 files ) is a special load on the processor and mainboard.

I hope my setup with the new mainboard stays stable for the foreseeable future.

cheers
Zsolt

Thanks KamilCSPS. Stumbled on to this after a while, and it does make the day lighter to read positive comments like this. A few years back, I was on a sabbatical for a while, then migrated to another team, and now recently came back to work closer to the web team.

Ruba and Brendan have been doing a great work community comments, so no doubt it’s been smooth riding for a long time by now :slight_smile:

1 Like

If you are suspecting hardware instabilities, one unique thing about the web platform build compared to other platforms might be that during the last stages (wasm-opt), there will be a moment when the CPU will be fully parallelized. That might stress the CPU more than usual, so any hardware instabilities could show up there.

There is a global environment variable EMCC_CORES=x that one can set to limit the number of simultaneous cores that will be used during that stage. The documentation for that is in Emscripten compiler docs: https://emscripten.org/docs/getting_started/FAQ.html?highlight=emcc_cores#why-is-code-compilation-slow

That might be a way to help diagnose hardware issues, e.g. by setting it to EMCC_CORES=1 will reduce memory stress and CPU stress for the build (and make it much slower, but worth for testing maybe)

Thank you for the idea, if it leads to a blue screen of death BSOD I would certainly try this option.
Now my case is solved with the mainboard change, but this may help other devs facing hardware issues.
New processors have immense performance and heat generation change capacities and mainboards cannot always keep up. (I’ve seen processor temperature rises like 10 celsius per second)

Having the exact error, making pythone admin did not do it for me, I am still lost, is it a hardware problem or a unity one?