Skip to content

Sprite Atlases

You can also find a video about it here:

By default if you use the asset shader with a sprite that’s inside of a sprite atlas you’ll see that the visual results that you obtain when using UV Effects are not the ones that you expect. This is because the Sprite Renderer knows that it’s a partial image (since it’s inside an atlas) but the shader doesn’t, which causes unexpected results. The problem with sprite atlases is that each sprite inside the atlas has an arbitrary UV range depending on its size. The Sprite Atlas setup normalizes the texture coordinates from 0 to 1 even though each individual sprite within the atlas has an arbitrary range. This setup will make UV effects work as you expect in images that are inside Sprite Atlases. The Wind effect is a great example. Compare how a sprite inside an atlas looks with the Wind effect when using the Atlas Setup versus when not using it:

The demo's boy, a sprite that shares its texture with the girl, with the same Wind material twice. Without the atlas setup he slides sideways from his feet up and gets cut off; with Sprite Atlas Auto Setup only his upper body sways and his feet stay planted

With this asset component buttons you can add and remove the Sprite Atlas Setup:

The All In 1 Shader component, with the Sprite Atlas Auto Setup and Remove Sprite Atlas Configuration buttons near the bottom

With the Setup button the SetAtlasUvs component will be automatically added:

The SetAtlasUvs component with Update Every Frame and Use Material Instance If Possible

This will manage everything for us. And in case we want to remove this setup we can press the second button and everything will go back to normal.

If we are using a sprite that won’t be changing we can leave everything as is after pressing the Setup button but if we are using an animation that swaps the sprite (a flipbook) we’ll need to check the Update Every Frame checkbox in the SetAtlasUvs component. Without it, SetAtlasUvs reads the first sprite’s place in the atlas once and then switches itself off:

A flipbook switching between the boy and the girl every second, both set up for the atlas. With Update Every Frame off the girl keeps the boy's place in the atlas, so she slides as a whole; with it on both bend from their feet

UI Images work the same but have a slight exception: for this to work every sprite inside the same Atlas must have a different material assigned. This can be achieved in several ways:

  1. Adding the AllIn1Shader component (this will create a fresh new material)
  2. Duplicating an existing image gameObject and then pressing the New Clean Material or Create New Material With Same Properties (SEE DOC) button
  3. Duplicating a saved material (Ctrl+D when selected) and assigning this new copy to the desired Image component

Make sure to enable Unity Sprite Atlases in the Editor Project Settings to properly test Unity Atlases:

Project Settings, Editor: the Sprite Packer Mode dropdown, with an arrow pointing at the Sprite Atlas V1 Always Enabled option

Finally keep in mind that there are 2 effects that don’t really work with this feature, these are: Rect Size and Polar Coords.