Sprite Atlases
Last updated
Last updated
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. With this asset component buttons you can add and remove the Sprite Atlas Setup:
With the Setup button the SetAtlasUvs component will be automatically added:
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:
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:
Adding the AllIn1SpriteShader component (this will create a fresh new material)
Duplicating an existing image gameObject and then pressing the New Clean Material or New Material with same properties button
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:
Finally keep in mind that there are 2 effects that don’t really work with this feature, these are: Rect Size and Polar Coords.