DEV Community

Cover image for A Practical Guide to Mobile Texture Memory Optimization in Unity: Formats, Mipmaps, Streaming & Atlases
GameOptim
GameOptim

Posted on • Edited on

A Practical Guide to Mobile Texture Memory Optimization in Unity: Formats, Mipmaps, Streaming & Atlases

🌐 Website: www.gameoptim.com

Texture Resources Optimization Overview

Texture memory is one of the largest contributors to GPU memory pressure in mobile games. Most inefficiencies come from format misconfiguration, resolution over-allocation, and incorrect Mipmap/streaming usage.


Texture Format

Incorrect texture formats remain a primary source of memory waste.

Common problematic formats:

  • RGBA32
  • ARGB32
  • RGB24
  • RGBA Half

Root Causes:

  • Batch processing misses due to naming inconsistencies
  • Runtime-created textures without explicit format assignment
  • Hardware fallback when target format is unsupported

Recommended Formats:

  • ASTC (mobile standard)
  • ETC2 (requires width/height multiple of 4)

Critical Notes:

  • ASTC + Mipmap requires power-of-two dimensions
  • Otherwise fallback to uncompressed storage may occur silently

Mipmap Behavior

Mipmap does NOT reduce memory. It increases memory usage by approximately 4/3.

Why:

Mipmap chain includes multiple levels:
1 + 1/4 + 1/16 + … ≈ 4/3 total memory

Benefits:

  • Reduces GPU bandwidth usage
  • Improves cache efficiency
  • Enables correct LOD sampling based on camera distance

Best Practices:

  • Enable for 3D assets (characters, terrain, particles, Spine)
  • Disable for UI textures with fixed screen-space usage

Resolution Waste Detection

Texture resolution directly correlates with memory usage.

However, high resolution does not always mean high utilization.

Key Metric: Mipmap 0 Sampling Rate

Definition:
Percentage of frames where GPU uses highest-resolution mip level.

Example:

  • 10,000 samples
  • 300 samples use Mipmap 0 → Mipmap 0 rate = 3%

Optimization Rule:

If Mipmap 0 usage < 5%:
→ Texture is likely over-provisioned

Extreme case:
Even Mipmap 0–2 combined usage < 5%
→ Severe memory waste

Practical Example:

  • 1024×1024 texture
  • 0% usage on Mip 0/1
  • 85% usage on Mip 2 → Safe downgrade to 256×256

Global Mipmap Limit & Texture Streaming

Global Mipmap Limit

  • Forces removal of specific Mipmap levels
  • Applied per Quality Level or group
  • Simple but visually destructive if misused

Texture Streaming System

Adaptive runtime system controlling mip levels based on memory budget.

Key Parameters:

  • Memory Budget (e.g., 200MB mobile target)
  • Max Level Reduction (controls initial mip stripping)

Execution Flow:

  1. Load non-streaming textures normally
  2. Load streaming textures with reduced mip levels
  3. Evaluate total memory usage
  4. Dynamically adjust mip levels based on budget

Limitations:

  • High CPU overhead due to continuous evaluation
  • Requires correct API-level activation (not just Editor toggle)
  • Ineffective if memory budget is misconfigured or too large

Read/Write Enabled

Enabling Read/Write doubles memory usage:

  • GPU copy + CPU copy

Most runtime textures do NOT require it and should disable this flag.


Atlas Creation Issues

Common pitfalls:

  • Atlas exceeds max resolution → multiple pages created
  • Loading one sprite triggers full atlas load
  • Poor grouping causes unnecessary memory spikes

Best Practices:

  • Limit atlas pages to 2–3
  • Group assets by usage frequency and scene dependency
  • Avoid partially empty large atlases

TextMeshPro Considerations

TMP introduces hidden memory costs:

Issues:

  • Large SDF atlas textures (Alpha8 format)
  • Dynamic fonts retaining .ttf in memory
  • Default font assets loaded unnecessarily

Optimizations:

  • Convert to static TMP after character set is finalized
  • Use Multi-Atlas Textures for better packing
  • Remove unused default fonts (e.g., LiberationSans, EmojiOne)

⚠️ Note:
Multi-Atlas and static TMP optimization paths are mutually exclusive in many workflows.


Final Takeaway

Texture optimization in Unity is fundamentally a data-driven sampling problem, not just a compression task.

Key levers:

  • Format correctness
  • Mipmap utilization efficiency
  • Resolution-to-usage ratio
  • Streaming strategy tuning
  • Atlas grouping strategy

Top comments (0)