How to know if a sprite is loaded from a SpriteAtlas or from the original asset?

Imagine this scenario :

  1. I have one PNG that I imported as Sprite (2D UI)
  2. I have created a SpriteAtlas in my Assets/ folder
  3. I have added the sprite inside the PNG in my SpriteAtlas
  4. I put a SpriteRenderer in a scene.
  5. I start this scene.

A) How can I know if the sprite is loaded from the SpriteAtlas or from the PNG ?
B) How can I be sure it’s the SpriteAtlas or the PNG that is loaded in my memory ?

You can check the Frame Debugger or Inspector (texture preview).

In code, print the texture name:

var sr = GetComponent<SpriteRenderer>();
Debug.Log("Source Texture: " + sr.sprite.texture.name); 

If it’s a single sprite it will print the sprite’s name, otherwise that of the SpriteAtlas.

  • Frame Debugger only shows me one render pass with a white texture
  • the Inspector when I click on the “Sprite” that is in my SpriteRenderer Component, points me to the original PNG

I tried with the Memory Profiler (in editor) and it is referenced three time :

  1. Once by the Sprite Atlas
  2. Once by the PNG
  3. once by “sactx-0-…” which I don’t know what it is…

I tried this code and it gives me
“Source Texture: sactx-0-4096x4096-ASTC 6x6-R3L4 - Cave - Atlas-ff29e3c8”
which seems to be the atlas I guess.

Which answer in my case :

  • The PSD Importer creates a Sprite Atlas itself if you have multiple sprites inside (multiple layers)
  • In my case, putting every single sprite from a PSD into a Sprite Atlas makes a better Atlas than the Atlas generated from the PSD Importer.

Worth noting that the Sprite itself remains as is, whether atlas or single. The Sprite reference is lightweight though. That third reference could be - but I’m not sure - simply a sprite frame reference meaning it represents the portion of the atlas texture from which the sprite is drawn. I believe this is still technically a texture type in Unity but it shares the atlas’ texture memory, it’s not a copy of the texture.