# How to Optimize Unity's Build Size

Unity is a powerful game engine, but when it comes to WebGL builds, it has a reputation for bloated file sizes - even for an empty scene. A default empty project can easily exceed **10MB**, which is a deal-breaker for web platforms like FB Instant Games or MSN where load times and size limits are critical to success.

But here's the good news: with smart configuration and deep understanding of how Unity compiles and packages WebGL builds, you can bring that size **down to just 2MB**, without sacrificing stability or core functionality.

This guide dives into exactly **how to strip Unity to its barebones**, eliminate unnecessary engine modules, trim code, compress assets, and configure the build pipeline to get a minimal WebGL export. We'll cover:

* 🚫 Disabling unused engine features and modules
* 🧹 Removing code stripping blockers and ensuring safe managed stripping
* 🛠 Fine-tuning PlayerSettings, and **IL2CPP settings**
* 🧬 Using correct compression format for Builds / Images / Sounds, etc
* 🗜 Setting up an efficient template and build structure

Whether you're building a hyper-casual web game or trying to squeeze your prototype onto a 5MB cap platform, these techniques will help you **shrink Unity to its lightest form possible.**

In this Guide we will take an empty unity project and will disable components step by step, change compression settings, change quality, shadows, etc and will show you step by step how it's affected Unity build size. Please note that we will do it on empty Unity project, to make the experiment more isolated.

{% stepper %}
{% step %}

### Create an empty Unity project for WebGL

We will use Unity 6000.0.23f1 + Built-In Render Pipeline.

<figure><img src="/files/KE5bjZIsEgjZmtZo0ZSK" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Switch platform to WebGL and do a build

We are doing this to understand initial build size of Unity WebGL projects with default settings.

<figure><img src="/files/o1sPT34lxw5NLXccHpJP" alt=""><figcaption></figcaption></figure>

We can see that initial build is around 9.7MB (which is quiet too much for WebGL). In this example we haven't changed anything yet, obviously if we change compression and other settings we can shrink build size (that's what we will do in the next steps).
{% endstep %}

{% step %}

### First thing to do!

Go to build settings and change `Code Optimization: Build Size with LTO`.

<figure><img src="/files/AxFhmKDRkQtW5AgcOMwO" alt=""><figcaption></figcaption></figure>

BOOM! We have already - build size 9MB.

<figure><img src="/files/WsdjcK6bz4kXeQy0mKD1" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Let's dive deep in player settings and optimize it

Let's change `Compression Format` to `Brotli` and enable `Name Files As Hashes` checkbox in Menu.

<figure><img src="/files/xX45POuPpBznK0WUrqkR" alt=""><figcaption></figcaption></figure>

Aaaaaaaaaand we are doing the next build!

<figure><img src="/files/UE5UNWCou8wFvx3GWdqF" alt=""><figcaption></figcaption></figure>

Now it's 6.8MB, so we are already optimized unity build from 9.7MB to 6.8MB, let's go further.
{% endstep %}

{% step %}

### Now let's change `IL2CPP Code Generation` to `Smaller Builds` and change `C++ Compiler Configuration` to `Master`

<figure><img src="/files/MtvpVKeCIwMecC5c4R0j" alt=""><figcaption></figcaption></figure>

And now we have 6.2MB build size.

<figure><img src="/files/LuVocwGTHxiMTArWuqEX" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Texture compression ASTC / DXT / ETC2

In our case, there will be no difference, because we don't use textures in current build, but depending on the platforms you can choose what suits for you. Generally we always recommend to turn on crunch compression on textures. We will not do new build here, because it will not change anything.
{% endstep %}

{% step %}

### If your game allows, you can change `Color Space: Gamma`

It will save additional 100KB for the build. Please be cautious, because rendering will change significantly, and personally `Color Space: Linear` looks much better.
{% endstep %}

{% step %}

### Strip engine code

`Managed Striping Level: High` (for this settings please be cautious, because sometimes it can "strip" needed code for your game, please test after enabling this checkbox).

Also enable texture mipmap stripping.

<figure><img src="/files/7mLup7WU1Hquxkmz4oHo" alt=""><figcaption></figcaption></figure>

Yeeeey! We are almost there, now we have 4.6MB build, 2 more MBs and we finish our optimization journey.
{% endstep %}

{% step %}

### Let's remove unneeded packages from the Project

Remove unneeded quality settings.

<figure><img src="/files/zXRl1DVocenRGSYcMCax" alt=""><figcaption></figcaption></figure>

Remove Graphic Settings and set to low (for example if you use "shadows" it will be better to fully disable built-in shaders and create custom "blob" shadow system).

<figure><img src="/files/oYYiywafNOTGImFDHpO4" alt=""><figcaption></figcaption></figure>

For example `New Input System` - is actually around 2.4MB, so if you don't use it, please remove `New Input System Package`, like in screenshot below, and finally we will get 2.2MB Unity WebGL build. We recommend using the `Old Input System`, as 2.4MB is quite a lot for web projects.

<figure><img src="/files/RcKYpMh8rpJwz1SdKqUs" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/gj1QjqKIjpUaTTwymGTd" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### And finally let's do a final build

And we have 2.2MB here! Quiet good for WebGL!

<figure><img src="/files/3pkaY0Dtbq8rrkkEr79j" alt=""><figcaption></figcaption></figure>

Your actual game will be bigger, because you will use textures / code / shaders / models, etc. But now being under 5 or 10 MB is much more achievable.
{% endstep %}
{% endstepper %}

Some Tools that will help you optimize your WebGL game:

* [Build Report Inspector](https://docs.unity3d.com/Packages/com.unity.build-report-inspector@0.1/manual/index.html) official Unity package, which helps to understand what’s uses more memory in your game
* [Asset Hunter Pro](https://assetstore.unity.com/packages/tools/utilities/asset-hunter-pro-135296?srsltid=AfmBOoohMPz62VnGxlFIptgBWuzUoIMmyM3YY1o3wSInbjJGcLCtcTq1) (paid)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.playgama.com/playgama/articles/how-to-optimize-unitys-build-size.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
