PackTextures creates lots of empty space in the atlas.

Hey,

I tried today the PackTextures function in Unity, but it creates a lot of unused space in the atlas.

if(CreateAtlas == true){
    Texture2D atlas = new Texture2D(AtlasSize, AtlasSize);
    atlas.PackTextures(AtlasTextures, 0, AtlasSize);

    byte[] bytes = atlas.EncodeToPNG();
    File.WriteAllBytes(Application.dataPath + "/../Assets/Atlases/SavedScreen.png", bytes);
    Debug.Log("FileSaved!");
}

I’m packing 10241024 textures in to an 10241024 atlas.

Is there a trick?

The black part at the top and right is unused space.
5037578--494012--failed_atlas.JPG

The image you posted isn’t very clear in illustrating what the issue is. If “1 2 3 4” refers to 4 sprites, it certainly appears to me that the four are packed as tightly as they could possibly be packed, and there’s obviously not enough space on the sides for another equally sized sprite. What’s the issue?

1 Like

Maybe it wasn’t the clearest picture, so here is a better one.
My point is exactly the black space around. Why are the images not scaled down to 0.5 of the original size (this would be 512512) so they would fit exactly into the 10241024 texture?
I think this is how it should behave because we are all working with power of 2, right?

5038847--494147--failed_atlas.JPG

1 Like

Can you show the inspector for one of the source images?

Sure,
here it is:

I’m facing the same problem.
If it is 1/2 resolution, it will fit perfectly, but for some reason an unnecessary gap is left.