U3DC.COM | 优三帝研究院

Menu

Unity Optimization Guide: WebGL Development Best Practices

PART 1

The common perception of Unity WebGL development is that while it’s convenient for development, it suffers from slow builds, sluggish content loading, lack of mobile support, and a host of other issues. The most frustrating problem, however, remains the painfully slow loading times. After comparing various H5 development frameworks, I was ready to abandon Unity WebGL entirely. But with the release of Unity 2020.1, there’s finally a glimmer of hope...

Recent tests comparing Unity Tiny, Laya, and Unity WebGL revealed that with proper optimization, Unity WebGL can significantly close the performance gap with Tiny and Laya, even if it still lags slightly behind. Below are cold-load test results for the same scene (local server, network impact excluded):

  1. Unity Tiny: 1.2 seconds

  2. Laya: 1.69 seconds

  3. Unoptimized WebGL (built with Unity 2018): 5.5 seconds

  4. Optimized WebGL (built with Unity 2020.1): 1.98 seconds

These results rekindled my hope and motivated me to dive back into Unity WebGL development.

Key Questions Addressed:

1. Why is Unity Tiny so fast?
Unity Tiny leverages DOTS (Data-Oriented Technology Stack), which combines three core technologies:

While DOTS represents the future of Unity, its official release has been delayed (originally slated for 2020). It’s worth exploring but may not yet be production-ready.

2. Why is Laya also fast?
Laya, a Chinese engine, emerged due to Unity’s initial neglect of WebGL optimization. It supports TypeScript/JavaScript development, eliminating script translation in browsers, and integrates ECS for component control. Laya is ideal for lightweight web games.

3. Why was Unity WebGL historically slow?

4. How did optimization improve Unity WebGL?


Optimization Steps for Unity WebGL:

1. Use Unity 2020.1 or newer.

2. Editor Settings:


PART 2

This section focuses on project-level optimizations to further reduce load times.

Post-Build Analysis:

After building, analyze the bundle via Console → Open Editor Log.

Optimization Strategies:

  1. Use AssetBundles for dynamic resource loading.

  2. Minimize plugins (they increase bundle size).

  3. Avoid fonts: Replace text with images if possible (Chinese fonts bloat bundles).

  4. Remove unused Packages (reduces Included DLLs size).

  5. Delete unused foldersResources and StreamingAssets are always included.

  6. Trim components: Remove unnecessary Colliders, scripts, etc.

  7. Simplify rendering:

    • Disable HDR on cameras.

    • Avoid real-time shadows.

    • Set Anti Aliasing to 2x/4x.

  8. Texture Optimization:

    • Use RGBA Crunched DXT5 format.

    • Enable MipMaps selectively.

  9. Memory Management: Apply standard garbage collection best practices.


By following these steps, a well-optimized Unity WebGL build can achieve near-native performance, making it a viable choice for web-based projects.

打赏
— 于 共写了3763个字
— 文内使用到的标签:

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据