Hello! I’m having trouble optimizing my game, specifically memory management. Textures use 90% of my memory, according to profiler, if we exclude runtime dll thingys.
For example, I have a 4096x4096 texture, and I cannot make it any smaller (Quality loss is unacceptable) and It takes up 5mb on disk (png file). Ingame, it uses only 1.4 mb (RGBA Compressed ETC2UNorm).
But when running the game, profiler says that this texture takes as much as 85mb uncompressed in my memory. This is insane numbers. Not 10, not 20, not even 40, 85+!!!
What am I doing wrong? My future project will have more 4k textures, if that keeps happening, I’m not happy. 2048x2048 textures lack quality and still weight a lot in memory. Am I missing something?
4096x4096 texture weights 8mb without crunch compression and takes exactly 8mb in memory while running!
If I use Crunch compression, texture weights 400kb but takes 64 mb of memory while running!
EDIT: More info, The issue seems to lie in Alpha channel. RGB texture takes 8mb in memory, but RGBA takes 64 mb! Exactly 8 times more! How??? It’s the same texture, I just set alpha source to none and get this result. I need Alpha!
The math for uncompressed RGBA textures is simple:
4096x4096x4 = 64 MiB
My understanding is that crunch compression is for disk space only. It gets decompressed at runtime. And the original crunched texture may even add extra memory usage. See: Unity - Manual: Texture formats.
If you cannot use lossy compression (DXT etc) then your textures will use the uncompressed size. That‘s what it is.
Do you profile a build or in the editor? In the editor, the memory profiler shows twice the memory size for textures. In a build, it should be the size that is displayed in the texture preview, unless Read/Write is enabled. This is apparently why it’s doubled in the Editor, because all textures are treated as if that’s enabled.
The preview actually shows disk size, not memory size.
Besides that, for snapshots taken from 2022 or newer, the Memory Profiler shows you all the relevant flags and values of the texture in Memory, which can help determine if e.g. it had to fall back to uncompressed because format was not supported by the device.