After upgrading from 2021 to 2022 or 2023 (or Unity 6) WebGL build size goes up dramatically.
My initial game’s (2021.3) build is 7.8MB compressed.
After upgrading to 2022, it gets about 20% more size to final build.
After upgrading to Unity6_preview (either from 2022, or directly from 2021) build size goes to 11MB.
About extra 3MB appear out of nowhere.
There is nothing in the package manager.
There is absolutely no meaningful reason from the build report.
I tried reimporting everything, deleting build folder, deleting Temp folder, clean build, etc…
There should be no reason - but the problem is there.
You’re moving to a new release that has new features in the runtime. For example Unity 2022 added support for Entities to WebGL. Entities is in a package but the package requires certain features that have to be provided by the runtime.
No but you can make a simple test: create new, empty projects in both editor versions and build for WebGL and check the difference. If it’s notable you could send a bug report.
Not an issue. If using URP, you need to strip a lot of the shaders. Take a look at this for cues on how to minimize your build size / overall best practices.
Our compiled brotli-compressed Unity 6 player with many packages & URP 3D, is 8MB total.
I agree that with the focus on mobile WebGL support, Unity 6 should make it easier for us to get a smaller build, instead a bigger build in this version!
It’s still extremely hard for the average dev if you have to do micro-management of every single setting to save a few kilobytes here and there
And with long build times for web platform it’s just a very tedious process to try every setting
Any way to have a build size estimation tool somewhere before building and while adjusting settings?
@kreso , it’s not very helpful, but I can verify the exact same thing. Our WebGL build size jumped from 8MB to 10MB when we switched from 2021 to 2022. All I can really do is empathize, but for us at least, build size is pretty critical and a 25% increase in bloat is disappointing. If you find anything that helps, please let us know.
With a build size this low, have you disabled the built-in modules that you aren’t using?
In my tests I could reduce the size by 1+ MiB by disabling such odd modules like Cloth, Vehicles, Wind, Nvidia/Amd, and so on.
Usually upgrading a project from the hub causes lots of bugs / outdated packages / out of sync meta files and bloat that gets built.
If your project is small, right click your scene, select dependencies, and export package to a fresh clean install of latest Unity 6 LTS. Will obviously need to re import and fix missing scripts, but I have to do this every time I upgrade to newer LTS. I don’t care if it wastes time becomes it always solves my problems. If you have a project that’s many hundreds of GBs I would not attempt this unless you want to throw many hours away on reimporting.
-Have you enabled the obvious ones like code stripping set to high / disk size with lto
-Disable all built in packages, re enable the ones you need.
-Crunch compress your textures or your atlas that has the uncompressed textures.
-Which texture compression method are you using (depends if target is mobile or desktop)
-Set mesh compression to high and mesh compression method to everything
-Make sure no realitime/baked lightmaps or reflection probes are bloating up build. A bug I found in Unity 6 was a default and very large unity cubemap being generated and not reported in build report underneath Lighting>Environment Reflections > Source (choose custom) and see if bugged cubemap pops up.
-Disable all the new web assembly settings underneath publishing settings and see the size difference.
-Run automated builds with every single setting turned on / off. Here’s example Unity 6 build that I got to be 2.04MB. Not much has changed from the original Unity 6 release, except the a few of the before mentioned web assembly /webgpu settings.
I made some slight progress on this. I was able to recreate the problem and submitted it as a bug. Unity confirmed it. I am waiting for an update.
Thanks for the suggestions @AdamandEveStudios , but unfortunately none of your suggestions help. I have already tried everything (and a lot more).
The problem is deeper. Here is the scenario that I submitted to Unity, you are welcome to reproduce it (it works 100% of the time):
Build a blank WebGL project (built in renderer). High stripping, optimize code for build size. Observe the build size is around 2.8mb (in Unity 2021).
Add (*)Dotween asset from Asset store, and build again. Notice that the build goes up to 5.5MB (2.7MB extra!)
The same happens in Unity 6.
The same happens in Unity 2020 (from 3.1MB → 5.4MB).
I still need to test in 2019.
More details:
For example I was able to narrow a specific file of Dotween, and a specific line of code.
In the UI module, if I remove ‘using Unity.UI;’ (the Image module) and it’s dependencies, the build size will go down 1.7MB
There are a few more dependencies that raise the size but this is a good example of the problem.
Could it be that IL2CPP is doing something and including Unity engine code 2x times?
Does it have to do with Unity changing built-in packages / dependencies (such as UI package) with higher Unity versions?
I really don’t know how that works. I can theorize but that won’t help me
What is next for me?
My next step will be to go further down in Unity version (to 2019) to see where this problem started happening. I will test specifically using Dotween because my project jumped few MBs without any reason and I suspect Dotween is the symptom. Removing Dotween from my project in Unity 2021 I “gain” 2.7MB less. And the only version of Unity i haven’t tried yet is the one I started my project in - 2019. So maybe there I will find another clue. It’s not much. But this problem is way over my ability anyways. I’m just scraping for details and submitting to Unity, if that potentially helps.
Down the line I also plan to check in with Unity if they were lucky to have any progress.
I hope to learn more, and I will keep this post updated.
Conclusion:
I put in a lot of effort to tweaking my build size, and I really hope I can remove the extra few MB, since size is one of determining factors for a successful WebGL game.
(*)Dotween is a tweening library. It should probably add around 100kb to a build, definitely not 2.7MB.
P.S. DOTween is not the problem. I tried doing the same with another tween library, it had the same effect.
P.P.S. I suspect this problem of increasing size compounds if there are more sources, over each higher unity version. Since I am observing size go up unreasonably with each Unity version.
Little protip you should ditch dotween and pick up prime tween instead
Zero garbage collection / so much faster than dotween.
Anyways yeah I think your doing something wrong with your build. For starters the absolute smallest build size possible on newest LTS with all packages and built in modules stripped is 2.24MB. I have tested every single setting. After importing dotween and applying the listed modules the new build size becomes 3.76MB. Removing those enabled modules and single UI package yields a build of 2.34B
Only Unity: 2.24MB
Unity + Dotween + Utility Modules: 3.76MB
Unity + Dotween Only: 2.34MB
The increase of 1.52MB is obviously because it is referencing the audio, physics, physics 2d, sprites, and ui built in unity packages / modules. These modules are not getting stripped. Manually disable these modules if you are not using them and they won’t be built.
And what’s surprising about the build size increasing when you add assets to your project? Not everything needs to be referenced by a scene to be included in a build. It would be interesting to see if the build size goes down (again: clean build) after entirely removing Dotween again.
That is not a problem, that’s how dependencies to assemblies work. Nothing has referenced Unity.UI before installing Dotween so UI isn’t included in the build. Then Dotween is added which references UI so the UI module does get added to the build. Works as expected.
Across Unity versions of course there is one difference related to Unity.UI: it used to be a package and eventually it became a built-in module. Also the older editor versions may reference older versions of the module/package which have fewer features and thus a smaller size.
Do note that the build report shows uncompressed sizes. If the textures are compressed or the build output is, then the resulting build (folder size) will be less than what the report shows.
I tested - in a fresh project the Dotween size of 2.7MB comes through including Unity dependencies. And believe it or not (I didn’t), the Unity’s UI brings in additional 1.5MB or so. I assumed it was way less.
Now finally, after checking my build again perhaps the build size is OK, and there is no problem. Oh boy!
Also worth noting for anyone down this path, Brotli compression brings my project down to 6.4MB (from manually compressed 7MB). I stopped testing with Brotli because my publisher requires uncompressed builds - so I would just compress manually to test for size (I wrongly assumed again that Apple’s zip compression would be very similar to Brotli).
Fun fact: if I further manually zip the Brotli-ed build, I get to 5.3MB heh.
Thanks again for all your input, your advice really helped me out to focus and try again with a clearer head.
@bigbrainz I will use the following tip for importing my project to Unity 6 one more time. Might be worth a shot as my project is not that big and I actually have all of dependencies in my main scene.
One final remark. I have imported my project from 2021.3 to Unity 6 and the final build size went up from 7MB → almost 11MB (if I built uncompressed and then used manual compression).
However, if I use Brotli compression the build size went from 6.3 → 6.7MB which I guess is reasonable.
One more note: with Unity 6 LTS (or perhaps already in Preview? I didn’t check) you can disable the splashscreen logo. This is known to use up several KiB (compressed in build, Build Report will list its size at over one MiB).
Yes - Unity 6 preview allows disabling splashscreen logo! This is currently my main motivation for upgrading.
Oh boy! I think build report started reporting the splashscreen in Unity 2023, and it reported as 2.7mb added to the build.
Which was incidentally match to the unexplained MB raise in my game at the time (also 2.7MB) so I was chasing that ‘splash screen problem’ as well.
And the final update. It makes me feel silly for not noticing this before, but perhaps there will be someone as silly as me out there so this may help:
There is a package called UI Elements (in the package manager it shows up as “UI Ele…”).
It was included by default and I assumed it was just the regular UI renamed or something, but I was wrong.
Removing this package was the final few extra MB - now my size is even a bit less than the previous Unity version (2021.3).