There’s an annoying limitation when using sprite atlases and packing sprites with lots of transparency that Unity trims away. I’ve reported this as a bug (IN-80480) but it was closed as expected behavior.
But first let me describe our use case:
Our animator is working in After Effects and we want to import frame-based animations into Unity. The animations should not only cover the changing art but also the movement, e.g. a frog sleeping somewhere and then jumping away
We’ve found the easiest way is to export huge textures that are mostly transparent for each frame of the animation and then pack them using a sprite atlas. Unity trims away the transparent borders, the packed atlas is pretty efficient, and the fixed pivot based on the original texture means that the movement of the animation on the texture is preserved.
Now for the limitation:
As long as the original textures are smaller than the atlas’ Max Texture Size, packing works fine and produces atlases that only contain the non-transparent parts of the texture and that can be much smaller than the original texture.
However, Unity refuses to pack sprites that are bigger than the Max Texture Size, even if the resulting atlas size would be well below it.
e.g.
I have two 4096x4096 textures A and B, both only containing a roughly 250x400 sized graphic, set to sprite mode Single and mesh type Tight.
If I pack those two sprites on an atlas with Max Texture Size 4096, they get packed onto a single 512x512 atlas texture.
However, If I set the atlas Max Texture Size to a smaller value (e.g. 2048), Unity fails to generate an atlas, complaining:
Packing Error: Sprite Atlas (Sprite Atlas Single) contain sprite(s) larger than its max texture size. It needs at least 4096.
This limitation seems arbitrary, since it’s clear those two sprites fit onto a 512x512 texture, well below the Max Texture Size limit.
Could this limitation be lifted?
With our current workflow, we want to use some big textures to have enough room to contain the movement. But we can’t increase the Max Texture Size because of platform limitations and are hitting this issue.
I don’t know the exact reasoning behind this limitation but it doesn’t seem to me like something that couldn’t be easily lifted. Can’t Unity just check the actual texture size of the sprite (Sprite.textureRect
) instead of the size of the original texture (Sprite.rect
)?