Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

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

Discussion in 'Profiler Previews' started by SebAsmodee, Dec 18, 2018.

  1. SebAsmodee

    SebAsmodee

    Joined:
    Oct 17, 2018
    Posts:
    4
    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 !
     
  2. alexrvn

    alexrvn

    Unity Technologies

    Joined:
    May 16, 2017
    Posts:
    57
    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).
     
    Menyus777 likes this.
  3. SebAsmodee

    SebAsmodee

    Joined:
    Oct 17, 2018
    Posts:
    4
    Ok thanks !
    Indeed sprite are not shown when I capture the player.
    By the way nice work !
     
    MartinTilo likes this.
  4. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,490
    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 :)
     
    skullthug, alexrvn and Sylmerria like this.
  5. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    @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?
     
    idyakonov likes this.
  6. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,490
    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.
     
  7. LeFx_Tom

    LeFx_Tom

    Joined:
    Jan 18, 2013
    Posts:
    88
    @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...
    upload_2020-5-20_14-10-23.png
    upload_2020-5-20_14-10-7.png

    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?
     
    idyakonov likes this.
  8. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,490
    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...
     
  9. LeFx_Tom

    LeFx_Tom

    Joined:
    Jan 18, 2013
    Posts:
    88
    @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...
    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 :(
     
    Last edited: May 20, 2020
    idyakonov likes this.
  10. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,490
    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.
     
  11. ZenTeapot

    ZenTeapot

    Joined:
    Oct 19, 2014
    Posts:
    65
    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.
     
  12. Sun-Pengfei

    Sun-Pengfei

    Joined:
    Nov 12, 2015
    Posts:
    37
    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:

    1. I didn’t use Resources folder. Both “Sprites” folder and Sprite Atlas assets exists in folder I created for them, right under Assets.
    2. 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!
    3. 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?
     
  13. Sun-Pengfei

    Sun-Pengfei

    Joined:
    Nov 12, 2015
    Posts:
    37
    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.
     
    MartinTilo likes this.