- Home /
The question is answered, right answer was accepted
How to get correct UVs for sprite in a Unity Sprite Packer-packed atlas?
I recently started using the built-in Unity Sprite Packer to create atlases and add padding to sprites, and it seems that Sprite.uv, as well as manually calculating the uvs using rect.min and max, both return UV coordinates within the original atlas, NOT the packed atlas present at runtime. Is there a way to get the correct UV coords for a sprite in its packed atlas?
EDIT: It turns out I was incorrect about Sprite.uv returning the old values, it does indeed return the coords within the new packed atlas. The point of confusion was that apparently if you have a reference to the atlas itself, at runtime that reference will still point at the old atlas, so if you're using that reference to apply the texture to a material, it'll apply the old atlas. This also means it'll include the old atlas in the build I assume, which seems like weird behavior to me but whatever.
In short: if you're using the sprite packer, make sure you have no direct references to the Texture2D asset itself at build time. If you need to apply the texture to a material, use Sprite.texture.