"Which Textures Are the Big Ones?" Dumping a List of Textures
Hello. I'm Hirayama from the Technology Department.
This one's short. I wrote a script that looks at the textures in a project and dumps a list like this:
5592405 1024x1024 RGB24 mips=11 faces=1 readable=False AssetStore/[検閲]/texture/body-blue.psd
5592405 1024x1024 RGB24 mips=11 faces=1 readable=False AssetStore/[検閲]/texture/body-yellow.psd
5592405 1024x1024 RGB24 mips=11 faces=1 readable=False AssetStore/[検閲]/texture/body-pink.psd
5592405 1024x1024 RGB24 mips=11 faces=1 readable=False AssetStore/[検閲]/texture/body-green.psd
5592405 1024x1024 RGB24 mips=11 faces=1 readable=False AssetStore/[検閲]/texture/body.psd
5130300 1047x1225 RGB24 mips=1 faces=1 readable=False [検閲]/Scenes/GameScene/Game/Sprites/bg_gradation_off.png
4872000 750x1624 RGB24 mips=1 faces=1 readable=False [検閲]/Scenes/[検閲]/Sprites/[検閲].png
4872000 750x1624 RGB24 mips=1 faces=1 readable=False [検閲]/Scenes/[検閲]/Sprites/_layout_point.png
4872000 750x1624 RGB24 mips=1 faces=1 readable=False [検閲]/Scenes/[検閲]/Sprites/_layout_9box.png
4872000 750x1624 RGB24 mips=1 faces=1 readable=False [検閲]/Scenes/GameScene/Game/Sprites/_layout_top.png
4872000 750x1624 RGB24 mips=1 faces=1 readable=False [検閲]/Scenes/GameScene/Game/Sprites/_layout_ingame.png
4872000 750x1624 RGB24 mips=1 faces=1 readable=False [検閲]/Scenes/[検閲]/Sprites/[検閲].png
4872000 750x1624 RGB24 mips=1 faces=1 readable=False [検閲]/Scenes/[検閲]/Sprites/[検閲].png
4872000 750x1624 RGB24 mips=1 faces=1 readable=False [検閲]/Scenes/TitleScene/Sprites/_layout_top.png
4375360 968x1130 RGB24 mips=1 faces=1 readable=False [検閲]/Scenes/GameScene/Game/Sprites/bg.png
2796202 2048x2048 PVRTC_RGB4 mips=12 faces=1 readable=False [検閲]/Scenes/GameScene/Game/Background/ingame_bg_3.png
Why did I make it?
I wanted to check whether the product I'm working on had any needlessly large textures. A familiar story.
How to use it
Drop the script into any Editor folder and Kayac/MakeTextureList appears in the menu. Run it, and textureList.txt
is created in the project folder.
You can read it as is in a text editor, or load it into a spreadsheet first, which is why it's tab-separated. You'll probably want to sort or filter by file name, format or size.
The number on the left is the size in bytes, a rough estimate of "how much memory it eats up". See CalcTextureByteSize in the script. It's long because it branches on every format, but what it does is simple enough (I haven't tested ASTC or BC, so be careful if you use those).
The total is also printed to the log when it finishes:

That makes it easy to get a rough picture of where things stand, or to see the effect of your reduction work.
How does it help?
On this project, we don't use AssetBundles and all the data ships inside the app itself, so there are size limits. We need to keep the apk and ipa from getting too big, and even when they fit within the limits, smaller is better for customers.
When you want to make things smaller, you want to know "which textures should I go after?", but you don't want to put much effort into such dull work.
The easy way is to sort them largest first and check the ones near the top for things like "is the size appropriate?" and "is the compression format appropriate?" And since I don't want to waste memory either, I also show whether Readable is set to true while I'm at it.
As a real example, I found four uncompressed 2048x2048 textures. That alone is 64MB. By setting the max size to 1024 and, since they were opaque, compressing them with ETC/PVRTC 4-bit, I got them down to 4MB.
Also, by sorting by file name and totaling only what's under a particular folder, you can quickly see things like "the stuff under X takes up most of the size". A spreadsheet is handy for this. If you know "halving the max texture size for this category saves X MB", it's easier to decide whether to actually do it. Something like "each character uses 1024x1024, for 200MB in total, but if 512x512 is acceptable it comes to 50MB. What do you want to do?"
Questions like "the UI sprites are compressed and look ugly, but how much bigger would they get uncompressed?" can be answered just as quickly the same way.
A game's data isn't only textures, of course, but if you're making an ordinary game, most of the size will be textures. If your game has a lot of audio data, it's probably worth doing the same for sound.
Implementation overview
First, get all the textures with AssetDatabase.FindAssets.
var guids = AssetDatabase.FindAssets("t: texture");
What comes back are GUIDs, so convert them to paths with AssetDatabase.GUIDToAssetPath and load them into memory with AssetDatabase.LoadAssetAtPath. Once that gives you a Texture, check whether it's a Texture2D or a TextureCube (and, if needed, whether it's 3D, a 2DArray and so on), and extract the information you need.
If you know the width, height, number of mipmaps, whether it's a Cube, and the format, you can estimate the number of bytes from that. It's an "estimate" because how much it actually uses in memory varies quite a bit with the hardware design (there are quite a few constraints like "even 1x1 uses at least 4KB"). There may also be restrictions when it's stored in a file, like "each mip level is rounded up to a size in 4KB units", so the reality is surprisingly hard to know. But such details don't really matter.
As for practical points to watch: it takes a fair amount of time, so show a progress bar, and wrap the whole thing in try-catch, because if an error occurs partway through and leaves the progress bar up, you can't do anything. That's about it.
Customization
The width and height are joined with an x, like "512x512"; separating them with a tab would make them easier to handle in a spreadsheet. Likewise, "Readable=True" would be more spreadsheet-friendly as just True. I mainly had a text editor in mind this time, which is why it's like this.
It might also be better to leave out files that aren't used. I didn't do that this time because I didn't want the
"is it used?" check to make the wait longer, but there are probably plenty of situations where it would be handy. In fact, the
list above includes files like _layout_top.png that look like they'd never go into a build.
If you do implement it, you could probably use the same approach as the technique from my article on checking dependencies, but I expect it to be quite slow, so it would be good to cache the results cleverly or reuse them for other purposes as well.
Closing
Everyone makes little tools like this, right? Some places probably keep track of their overall asset volume in more sophisticated ways, and some may take the more advanced approach of "not needing to keep track in the first place". In that sense, this article isn't worth much.
By the way, a tool like this is a good exercise for getting used to editor extensions. It might even be worth deliberately not sharing it across teams, and having someone inexperienced on each team build their own. If you make everything common and shared, you can lose the "training people" side of things.