I'm trying to reduce a Unity WebGL build size which, for the data asset, is currently at 30 Mb. I installed the Build report inspector. On clicking the "Source assets" tab and choosing "Size" it showed the top entries were images. Fine. But all the sizes reported were between 4 and almost 30 times the size of the file on disk. Is this just a bug / artifact of the build reporter or a genuine problem which I need to address to reduce the build sizes?

** Edit **

Two of the files are text files. Their size in unity build report is the same as that on disk. Why?

large image sizes on build report

** Edit 2 - after Ed Marty's answer **

Using low quality with crunch compression at 70 results in slightly lower image quality but it went from 10 Mb to 300 kb, i.e. 30 times smaller size (and about 10x smaller than actual file size on disk).


Unity projects don’t include the source file in the project when building. Instead, every image is converted during import to a format useful to the GPU, as set by you in the import settings for that image. These tend to be larger, especially if an uncompressed format is chosen, and especially if the source image is in a compressed format (eg. jpeg, or png if many neighboring pixels are identical). For example, a 1024x1024 image stored in RBG-24 format uses 3 bytes per pixel, times 1024*1024 pixels, equals 3 MB. A 2048x2048 image in the same format uses 12 MB. It also likely includes mipmaps, which increases the size. A 2048x2048 image in the same format with mipmaps would be about 16 MB.

If a compressed output format is chosen instead, this can significantly reduce the file size, at the expense of image quality. Depending on platform, there are several formats and compression levels to choose from with varying trade offs between quality and size.

See here for more details about specific formats per platform. https://docs.unity3d.com/Manual/class-TextureImporterOverride.html

Compare all this with the png format for example, which has lossless compression built in. Even a gigantic 4096x4096 png image can be as small as a few kB if it’s mostly empty.

Of course none of this applies to text files, which don’t need to be modified for GPU optimization.

So to decrease app size, your best bet is to change compression settings, decrease image size, and potentially turn off mipmaps for a bit more savings, if you don’t need them, otherwise that could decrease performance.

An alternative I would not recommend would be to store the source images in the streaming assets folder, and load them manually at runtime. An option, but not a good one.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.