I made a sprite atlas, but how do I use it?

I’m trying to use the sprite atlas instead of creating my of sprite sheets to I can optimize space better. I followed some simple tutorials and dropped a bunch of sprites into my atlas, and now I see a preview that shows all sprites packed tightly into only three sheets instead of ten.

But now that I have it, I can’t seem to do anything with it. I can view the image it says it created, and see how all these different sprites are packed together, but how exactly do I actually use these sprites in my game as opposed to the source sprites I used for the atlas?

2 Likes

I’m honestly surprised that I can’t find an answer here.
Every tutorial I’ve looked at shows how to make this, but not how to use it.

2 Likes

I believe you then use the source assets, but in build the atlas is used instead… at least that’s how I understood it.

But I don’t know, the sprite system in Unity has been very awkward and buggy to use for me. I ended up just making efficient meshes packed in an atlas and using those (I use spriteUV) and not having to deal with sprites at all.

Sprite Atlas packs all of the sprites you referenced for packing into individual textures, and when Unity needs to render/reference one of the sprites you’ve packed, it will automatically load and use the sprite that is packed into the textures that was generated instead of the standalone sprite.

You don’t have much control over this process, and you cannot reference these generated sprite atlas textures as far as I remember. Maybe in the Version 2 of sprite packer you can, but I haven’t looked into that much.

Any specifics on what you are trying to accomplish?

2 Likes

Oh; I thought I would pack everything into the atlas and then when I want to use a given sprite I’d have to reference the asset through the atlas.
So I can just keep grabbing the sprite as I originally placed it in my asset folder, and the engine will automatically chose to use the version from the sprite atlas? That’s actually pretty handy.

1 Like

You can use Sprite Editor

Yes, that’s pretty much it. You just reference the usual sprites in your project as you would normally, and when you make a build or enter playmode with the sprites contained in an atlas, Unity will load the atlas and use the sprite located inside of it, just be sure to enable the sprite atlas setting in the project/player settings.

Just be aware of the following: If you have really large atlases (8k size for example), and you reference a single sprite inside of it, the entire atlas will be loaded into memory, which may be undesirable, so try to pack sprites that will be used together.

2 Likes

So if we are debugging we won’t see reduced draw calls inside the editor?

It seems like the editor inconstantly uses the atlas. I’m in 2020.3. Why would this fluctuate?

@Marscaleb I use Texture Packer Pro. It generates a ‘best-fit’ texture atlas and includes a json document that tells Unity what sprite is where