In this lesson, you will learn how to shrink your game's memory footprint and improve performance by configuring texture compression and grouping sprites into atlases.
The Cost of Raw Textures
When you import an image into Unity, it starts as a raw file. If you leave these files at their default settings, your game will consume a massive amount of VRAM (Video RAM). To fix this, you must adjust the Texture Type and Compression settings in the Import Settings inspector. By selecting a platform-specific format—like ASTC for mobile or DXT for PC—you tell Unity to compress the image data. This makes the file size much smaller, helping your game run smoothly on devices with limited memory.
Reducing Draw Calls with Sprite Atlases
Beyond individual file size, there is the issue of "Draw Calls." Every time the CPU tells the GPU to draw an object, it sends a command called a draw call. If you have 50 separate sprite files, the GPU may have to pause and switch textures 50 times, which is very slow.
A Sprite Atlas solves this by bundling multiple smaller sprites into one single large texture file. Instead of the GPU switching textures for every character or item, it keeps the entire atlas loaded. Because all the objects share that one "page," the GPU can draw them all in one single operation.
How to use Sprite Atlases:
- Right-click in your Project Window and select Create > 2D > Sprite Atlas.
- Drag your individual sprite files into the Objects for Packing list in the Inspector.
- Click Pack Preview to see how Unity combines them into one sheet.
Once a Sprite Atlas is created, any GameObject using a sprite inside that atlas will automatically reference the combined texture. This reduces your draw calls significantly, meaning your game can display more objects on screen without stuttering.
Always remember: the fewer textures the GPU has to "swap" while rendering a frame, the faster your game will perform. By compressing your individual textures and grouping related assets into a single atlas, you ensure your project remains lean and performant.
Key Takeaway: Compressing individual textures saves precious memory, while Sprite Atlasing combines multiple images to reduce draw calls and speed up rendering.