Key takeaways
- Memory is the main constraint: set the heap size on purpose and test the largest level on a phone.
- Garbage collection only runs between frames on the web, so avoid allocating in Update.
- Strip code, compress with Brotli and use mobile texture formats to cut the download.
- Load content on demand with Addressables, and release it when you are done.
- Leave Application.targetFrameRate at its default and profile on real devices.
How Unity web builds run in the browser
A Unity web build compiles your C# to WebAssembly through IL2CPP and runs on the browser's main thread inside a single memory heap. Two consequences shape almost every tip below: the browser decides how much memory you get, and anything slow on the main thread shows up as a dropped frame.
Memory optimization
Most Unity web builds that fail on phones fail from memory, not from rendering. When the heap runs out, the game simply stops.
Set memory limits deliberately
- Set the initial and maximum memory in Player Settings → Publishing Settings to what your game actually uses, plus headroom.
- Test the largest level on a mid-range phone; phones grant far less memory than desktops.
- Watch for memory that only ever grows between levels. That is usually a leak, not a limit.
Garbage collection
On the web, Unity can only collect garbage between frames, never in the middle of one. A frame that allocates heavily grows the heap before anything is freed, and the next collection causes a visible hitch. The fix is to allocate nothing in per-frame code:
- Pool bullets, particles, enemies and UI items instead of instantiating and destroying them.
- Cache component lookups, arrays and strings; avoid string building, LINQ and boxing in
Update. - Use non-allocating APIs such as
Physics.RaycastNonAlloc, and reuse the result arrays. - Load and unload in clear moments (a level start, a menu), never mid-play.
// one buffer, reused every frame: no garbage
readonly RaycastHit[] hits = new RaycastHit[16];
void Update() {
int n = Physics.RaycastNonAlloc(transform.position, transform.forward, hits, 20f);
for (int i = 0; i < n; i++) { /* use hits[i] */ }
}
Addressables, the successor to asset bundles
Ship the smallest build that gets players into the game, then fetch the rest on demand. The Addressables package builds on asset bundles and handles loading, dependencies and memory for you.
- Keep the first level, menus and core UI in the initial build; mark later levels, music and cosmetics as separate groups.
- Call
Addressables.Releasewhen you leave a level, or memory keeps climbing. - Keep remote content inside your upload and load it with relative paths so it works inside the Halftone player.
Textures and audio
- Use ASTC or ETC2 texture compression for mobile browsers and keep textures no larger than they appear on screen.
- Disable Read/Write on textures and meshes you never touch from code; it doubles their memory.
- Stream long music instead of decompressing it into memory on load.
Smaller builds, faster loading
- Managed Stripping Level: High and IL2CPP Code Optimization: size remove code you don't use. Test afterwards: reflection-only code may need a
link.xml. - Brotli compression gives the smallest download. If the server doesn't send the matching headers, turn on Decompression Fallback so the build still loads.
- Remove unused packages and render pipeline features; each one adds to the download.
index.html at the top level. Enable Decompression Fallback when you use compression, so it loads correctly from our servers.Profile memory and performance
Measure before you optimize. Make a Development Build with Autoconnect Profiler, then use the Memory Profiler package to compare snapshots: one at the menu, one after a level, and one after returning to the menu. Anything that grows between the first and third is leaking. Check the browser's developer tools as well, since the memory the browser reports is what decides whether a phone keeps your game alive.
Frame rate and frame pacing
In the browser, the page paces frames. Leave Application.targetFrameRate at its default so the browser matches each screen's refresh rate; that gives the smoothest result. Lower it only where nothing moves, such as menus or pause screens, to save battery, and restore it when play resumes.
Mobile browsers and touch input
- Unity 6 supports running web builds in mobile browsers, so plan touch input and on-screen controls from the start.
- Use the Input System package for touch, mouse and keyboard from one set of actions.
- Declare portrait or landscape when you upload to Halftone; we ask players to rotate before the game starts.
- Keep UI inside the safe area of notched phones.
WebGPU in Unity 6
Unity 6 includes an experimental WebGPU graphics backend. It can bring better performance and modern rendering features, but keep WebGL 2 as your shipping target until you have tested WebGPU on the browsers and devices your players use.
Unity web build checklist
- Memory settings chosen on purpose; largest level tested on a phone.
- No allocations in Update (checked in the Profiler).
- Code stripping on; build tested after stripping.
- Brotli or Gzip compression, with Decompression Fallback enabled.
- Mobile texture compression; Read/Write disabled where unused.
- Addressables released between levels.
- targetFrameRate left at default during play.
- Touch controls and orientation tested on iPhone and Android.
Further reading
- Unity Manual (Web platform section: memory, compression and optimization)
- Addressables documentation
- Memory Profiler documentation
- On Halftone: HTML5 game quality guidelines and HTML5 game development tips
Frequently asked questions
Why does my Unity WebGL game crash on mobile?
Usually it runs out of memory. Phones give the browser far less memory than desktops. Lower the heap size you request, cut texture sizes, avoid per-frame allocations and unload content between levels.
Should I use Brotli or Gzip for Unity web builds?
Brotli gives the smaller download. It needs the server to send the right Content-Encoding header; if you cannot control that, enable Decompression Fallback so the build still loads.
How do I reduce garbage collection spikes in Unity WebGL?
Allocate nothing in per-frame code: pool objects, cache arrays and strings, avoid LINQ and boxing in Update, and use non-allocating APIs such as Physics.RaycastNonAlloc.
Is WebGPU ready for production in Unity 6?
It is experimental in Unity 6. Test it on your target browsers and devices, and keep WebGL 2 as the build you ship until you are confident.
Which texture compression should I use for mobile web?
ASTC or ETC2 for mobile browsers. Keep textures no larger than they appear on screen and disable Read/Write where you do not need it.



