DEV Community

Yiren Labs
Yiren Labs

Posted on Originally published at atlas-errors.petersoncool.workers.dev

Unity: the atlas cannot fit a sprite during packing

What you see

Pressing Pack Preview, or a build that packs atlases, throws ArgumentException: Atlas "foo" (2048x2048) can't fit sprite "texture2" (3840x1080). The exception carries a multi-line stack trace into the 2D packing pipeline. The atlas fails to produce a packed texture, and every sprite sourced from it shows the default white or missing sprite in the scene.

Why it happens

Unity's default IPackerPolicy constrains each atlas to the target platform's maximum texture size and power-of-two rules. The policy first estimates the atlas rectangle, then asks whether each sprite's bounding rectangle still fits. When one source texture is wider or taller than the side the policy allowed, OnGroupAtlases rejects it and throws this ArgumentException. The sprite itself is valid; the conflict is between the source pixel size, the atlas Max Size, and the texture limits of the target platform.

Confirm it

Select the source texture in the Project window, open the Texture Importer, and read its Max Size under the texture settings. Then select the SpriteAtlas asset and read its Max Size in the Inspector, alongside the Objects for Packing list. A healthy case keeps the sprite's packed width and height below the atlas rectangle the policy allows for the platform. The broken case is exactly what the exception prints: a 3840-wide sprite against a 2048-side atlas. You can also scan the imported texture metadata:

Select-String -Path Assets\**\texture2.meta -Pattern "maxTextureSize"
Enter fullscreen mode Exit fullscreen mode

Fix it

The direct route is to shrink the sprite or lower its importer Max Size so it fits the atlas rectangle. The importer metadata for that texture looks like this:

--- !u!111 &1
TextureImporter:
  maxTextureSize: 2048
  spriteImportMode: 2
Enter fullscreen mode Exit fullscreen mode

Lower the value on the source texture, apply the importer, and return to the atlas to run Pack Preview again. If the art must stay at its native size, the alternative is a custom IPackerPolicy that allows a 4096 atlas, selected in the Sprite Packer window under Edit > Project Settings > Editor. After repacking, verify that the preview atlas shows the flagged sprite inside the packed texture and that the exception no longer appears in the Console.

The exact engine message, with its source location, is documented here: https://atlas-errors.petersoncool.workers.dev/error/unity-atlas-cant-fit-sprite/

Options

If you would rather not balance sprite sizes and atlas limits one asset at a time, the same fit check can be run across a folder offline: the full version is $19 and there is a free sample on the fixer page.

Batch atlas fit check across folders: https://atlas-errors.petersoncool.workers.dev/fixer/

Companion reference page for this engine message: https://atlas-errors.petersoncool.workers.dev/error/unity-atlas-cant-fit-sprite/

Top comments (0)