Sprites are loaded in memory even if there are in a sprite atlas - Captured in Editor

Hi,

I have report a bug ( Case 1110373) for a strange behavior of sprite atlas.
When I use sprite atlas for all my sprites and I capture memory with this tool, the windows shows me that individuals textures and atlas textures are loaded in memory at same time.

Can you confirm me that behavior is not a bug from the profiler tool but from atlas system ?

Thanks !

Hi! Afaik, we crawl all live native objects (eg: Texture2D) with the memory profiler. As such if they are loaded in memory, the memory profiler will display them. Afaik the SpriteAtlas will pack it’s Sprites when you enter Playmode hence it would need to read from said resources during OnEnterPlayMode, furthermore those resources are already loaded via edit mode as Sprites will use their Texture2D refs instead of the SpriteAtlas while in edit mode, as such I’d expect to see both the textures referenced being loaded in memory and the sprite atlas itself (Editor only).

1 Like

Ok thanks !
Indeed sprite are not shown when I capture the player.
By the way nice work !

1 Like

I’ve renamed the topic so it’s search friendly and removed the Bug tag since it isn’t one (the corresponding bug has been closed as By Design).

Just to add to Alex’s explanation: When capturing a Play-mode player there is no way to cleanly separate between the player and the surrounding Editor so you’ll just get both. As a result, you’ll see Editor UI, various Assets and e.g. RenderTextures for Camera Previews and similar stuff in the snapshots.

So the long and short of it is that for most intents and purposes you should inspect snapshots from built Players on your target platform. This is mentioned in the Documentation but we’ll look at ways to make this more obvious in the UI as well. Thanks for highlighting that this is still missing some clarity :slight_smile:

3 Likes

@MartinTilo @alexrvn We’re seeing this in Builds on device when we memory capture despite having our SpriteAtlases setup correctly in Unity 2019.2.20f1.

Any idea what would cause those sprites to show up separate from SpriteAtalses?

1 Like

Hi @Ben-BearFish ,
Do you mean they show up as Texture2D with native memory behind them or as Managed wrappers for the Sprite objects? Also, are you using AssetBundles? Sometimes incorrect AB setup might pull in duplicated resources.

@MartinTilo same issue here…when i profile a WebGL Development-Build, the textures show up twice in the memory sample, that i took from the autoconnected player.
Unity 2019.3.11f1 here…


We don’t use AssetBundles and i don’t know how to tell, if this is a managed wrapper or something like that. The memory-amount is summed up for both objects…and this is a bit painful on WebGL for smaller (aka mobile) platforms…

Any help/explanation?

1 Like

I don’t see any dublicated textures in your screenshots. I see one Texture named software 1 and one texture that has a reference to it from a sprite named software 1.

Regarding differentiation into managed and native objects, you’ll need to use the Memory Profiler package to inspect these snapshots to be able to tell what is what.

Btw, not sure if that’s happening here because I can’t see the dublication here but: if a sprite atlas is too big, it gets paged and then every page of it shows up under the same name…

@MartinTilo the texture software 1 resides (as sprite) in the folder, that gets packaged into the atlas “DisplayContents” and is listed in there as sprite again…
5875474--625594--upload_2020-5-20_15-1-55.png
That is what i meant…it is only present once in the project and shows up twice in the profiler…

I’ll check the package to dig deeper though…

edit:

Can’t use the package right away, because i build for WebGL and this is not supported by the memory profiler :frowning:

1 Like

Have you tried this? We should have actually fixed support for WebGL in 2019.1. You’ll have to do a Auto Connect Build & Run build to hook up the profiler but taking snapshots should then work.

I’m seeing a similar issue in memory profiler. A large texture is individually shown in the memory profiler as native object(8MB), while it’s actually packed in a huge atlas( which I can also find in the memory profiler). It’s profiled standalone on MacOS and Android, same result. The unity version is 2021.3.15f. The asset that references this texture is an animation clip. No other textures show this behaviors. Only the huge atlas is added to addresable. The original texture is not even referenced in addressable groups. Not sure what’s going on.

Hi, I’m encountering the same problem. Please help me check out this snapshot:


As shown in the above screenshot of a memory profiler snapshot on andoid device, sprites(shown in green box) are actually all packed into sprite atlas(shown in blue box). Is this supposed to be right? If not how can I solve this?

Some details:

  • I didn’t use Resources folder. Both “Sprites” folder and Sprite Atlas assets exists in folder I created for them, right under Assets.
  • To get a sprite, I tried return _atlas.GetSprite(key);, or just a reference directly to the Sprite itself public Sprite spriteExample;. The memory snapshot showed almost the same result. Same draw calls, sprites seperately loaded, memory usage are almost the same. Can someone confirm if the second way is correct to use sprite atlas? Thanks!
  • I know the profiler also profiles Editor related stuff, however my memory snapshot is taken from a real android cellphone. So what we see here are all the memories on the device right?

I’ve found the answer myself. On some of the images I used particle system to make it fancier, in which under the shape part, I used the same texture as the emitter’s shape. This caused a duplicate texture in the memory. I don’t have a good solution now, so I just deleted the particle systems. Saving about over 100 MB memory.

1 Like