- Home /
How do I get the bounds of a sprite on its sprite atlas?
I used to make sprite atlases manually and set the texture's sprite mode to multiple, this let me use sprite.bounds.size to get the size of the sprite on the texture. Now I use the 2017 Sprite Atlases and set every individual texture's sprite mode to single, but sprite.bounds.size just returns the original texture size. Any idea how to get the size of the sprite's box on the sprite atlas? Thanks!
By that you mean SpriteAtlas.GetSprite().bounds.size returns the size of the whole atlas?
Hiya, no, sorry if it's not clear. Sprite.bounds.size returns the size of the whole texture when the sprite mode is set to single whether it is packed in the new sprite atlas or not. Is using SpriteAtlas.GetSprite() the only way to do it? Using a string to find the sprite seems potentially messy.
Looking up the API there's not much else you can do with it. It doesn't seem to be for lookup purposes since every Sprite related call clones it too. But since you're packing those sprites you could also just create a seperate list for the sizes matching a particular atlas and save it during edit time into a scriptable object for later use.