Loading lessons...
Texture Compression and Streaming
Texture Compression and Streaming
Textures are often the largest contributor to a game's memory footprint. Understanding compression formats and streaming is essential for optimizing memory usage across platforms.
Texture Compression Formats
Different platforms support different compressed texture formats. Compressed textures use significantly less GPU memory than uncompressed RGBA textures.
| Format | Platform | Notes |
|---|---|---|
| DXT1/DXT5 (BC1/BC3) | PC/Console | Standard for Windows/DirectX |
| ETC2 | Android (OpenGL ES 3.0) | Required for Android store |
| ASTC | iOS and modern Android | Best quality-to-size ratio |
| BC7 | PC/Console | High quality, HDR support |
Setting compression in the Inspector:
- Select a texture asset.
- In the Inspector, choose a Compression setting (None, Low, Normal, High).
- Override per-platform under the platform tabs (Android, iOS, etc.).
Import Settings That Affect Memory
- Max Size: Limit the maximum dimension (e.g., 2048 or 1024). Reduces memory at the cost of detail.
- Generate Mipmaps: Creates smaller versions for distant textures. Uses 33% more memory but prevents aliasing.
- sRGB (Color Texture): Enable for albedo/diffuse textures, disable for normal/metallic/roughness maps.
Texture Streaming (Mipmap Streaming)
Texture Streaming loads only the mipmap levels needed for the current camera distance, reducing peak memory usage.
Enable globally: Edit > Project Settings > Quality > Texture Streaming (enable Streaming Mipmaps).
Per-texture: Select the texture asset, enable Streaming Mipmaps in the Import Settings.
// Check streaming status at runtime
Debug.Log("Desired mip: " + Texture.streamingTextureLoadingCount);
// Force a specific mipmap level (0 = full resolution)
Texture2D.streamingMipmapUploadThresholdSize = 32 * 1024 * 1024; // 32 MB
Texture Atlases
A texture atlas combines many small textures into one large texture. This reduces:
- Draw calls (one texture swap = one material = one batch).
- Memory overhead from texture headers.
Sprite atlases in Unity are created via Assets > Create > 2D > Sprite Atlas and managed automatically by the engine.
TL;DR
- Use platform-appropriate compressed formats (ASTC for iOS, ETC2 for Android, DXT for PC).
- Limit Max Size per texture and disable mipmaps for UI elements.
- Enable Mipmap Streaming to load only the detail level the camera needs.
- Texture atlases reduce draw calls and memory by combining multiple textures.