The question is answered, right answer was accepted
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.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
3 People are following this question.
Assigning UV Map to model at runtime
Sprite Packer Causes Unity to Hang on 5.5.0f3
loading sprite from atlas in script
Automatic mesh combine and texture atlasing
How can I use atlas sprite as texture for a material?