Hello Guest

Author Topic: Sprite Batcher loading all unecessary atlas  (Read 3542 times)

McTomas

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 13
    • View Profile
Sprite Batcher loading all unecessary atlas
« on: August 21, 2014, 05:23:35 pm »
Hi,

I just encounter a very strange bug and very problematic one, but I’ll do my best to explain it to you.
So in my RPG game, before I go to gameplay I have an Main Menu. Inside of the main menu I have two buttons, a button to go to my play scene and a button that goes to the Heroes Menu, Inside of the Heroes Menu I go to the Spells Menu.
Each Menu has it’s own atlas and prefab and works independently.

Everything works perfectly, but when I builded my game to low end mobile devices I noticed that my game runner very very slow. After a lot of search and debugging I found the problem (a very very strange one).

I noticed that tk2dspritebatcher loads all my sprite collections textures (even the ones not needed for the batcher).
Probably you will be saying that I’m doing something wrong and I’m adding an sprite without know (that was my thought also), but after a lot of digging and searching I found out that I’m not adding nothing from other atlas.

This is also a very strange bug that only happens in some occasions, that is getting very hard to solve the problem. For example:

- When I open the app(game), and enter in the main menu, everything is loaded correctly (and in the main menu I have some objects with sprite batters).
- When I open the heroes menu from the main menu, for some reason that I don’t know why I have every single atlas from the sprite collection I created loaded (but not being used).
- When I open the spells menu from the heroes menu, I have only the necessary atlas loaded and everything that unnecessarily added from the heroes menu is removed from memory.
- When going back to the main menu, noticed that everything is back to normal.

So with this, I investigated into the heroes menu. After a lot of digging noticed that the single button to open the spells menu (from the heroes menu) is loading every single atlas from the my sprite collections. Well I found this very strange because the button is exactly the same the ones I used in the main menu or spells menu (with the only difference is the tk2dtextmesh above it).
I dig more into it, and after some desperation I removed the sprite batcher from the button (because the button is composed with 4 sprites), and noticed that all of the sudden I didn’t had the unnecessary atlas any more.

So my question is, how can a tk2dSpriteBatcher load all the unnecessary atlas from my sprite collections, and how can I fix that?

Cheers,

Miguel

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprite Batcher loading all unecessary atlas
« Reply #1 on: August 21, 2014, 05:33:15 pm »
All atlases from all referenced sprite collections are loaded in Unity, regardless of if you use them or not. Are you using atlas spanning - if so, you can't rely that unused atlases wont be loaded, treat it as though all atlases in a sprite collection will be loaded.

McTomas

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Sprite Batcher loading all unecessary atlas
« Reply #2 on: August 21, 2014, 05:39:01 pm »
Ohhhh ok, I’ll look into that. Thank you :D