Hello Guest

Author Topic: Sprite, Atlases and memory management Pt.2: The return of AnimatedSprites  (Read 4679 times)

Dajuice

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 45
    • View Profile
Hey there! Long time no see! So my question is rather simple: any way to get the name of animations at runtime? My researches led me to this sad answer: http://answers.unity3d.com/questions/192441/get-the-name-of-an-instances-prefab-at-runtime.html But maybe you have the name stored in a dark corner of your script?

I need this so I could easily include animated sprites to my memory manager...

Also I was wondering if you could think about this feature of memory management: nothing to manage, but only the part where , with a function call, you can make a sprite lose all links to it's texture so memory can be freed.
While the texture's gone, all scripts seems to run normally, but nothing that touches texture manipulation runs, so you could change spriteId and Play/Stop SpriteAnimations still works, but with no texture.
Then with a call, you put back the texture and it is updated accordingly.

As always, thanks :)

Dajuice

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 45
    • View Profile
Must I understand there is absolutely no way to access animated sprite's name?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
No, I just missed that initial thread somehow.
If you need the animation library name, its just
sprite.anim.name
If your animation library was in a resources, you could reload it using this name, but not if it was in a subfolder within the resources folder.

The texture memory stuff is really tricky in Unity, and not nearly as easy as it should be :(
You win some (super easy data/dependency serialization) you lose some.

Dajuice

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 45
    • View Profile
Well, now that the game's finished and on Ouya (yay^^)  I now have to come back to those tricky and depressing questions about memory management...

First, thanks for the answer, second, you tell me that even if there is no obvious (do not mix with obviously no) link to a sprite sheet from any sprite on the stage, the texture will still won't be GCed after RemoveUnusedAssets? This is a rather disappointing conclusion if this is what you meant...

Thanks for this, I think I'll have to rethink my memory management all over (I cannot afford to completely unload my pages, or I'll have to rethink all the game structure)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
There will be the ability to unload sprite collections (unloads textures and stuff) in the next version of 2D Toolkit.

Dajuice

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 45
    • View Profile
Whoa great! Can't wait for this update and keep up the good work!