Hello Guest

Author Topic: Managing Texture Memory And Seamless Loading / Streaming. Best Practices?  (Read 4633 times)

NMD

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Hi!

We are using 2D Toolkit and have A LOT of high res sprites.

Our current scene loading setup is sort of odd and buggy. I don't want to waste too much of your time detailing things but basically....

To get memory back at the end of each level we had to manually find and destroy everything, then load a "blank" scene that just loads the next.

I'm in the processes of changing things up and trying to figure out the best ways to do so. I'm posting here looking for some 2dtk specific info but any general advice on how to approach stuff would be great.

The new plan is still being worked out but....

All of our scene specific sprites are in their own collections. And all of our sprite objects are prefabs, which use PoolManager to pool instances. We have multiple spawn pools, one for persistent objects that are used though the whole game, then each scene also contains pools specific to that scene only.

At the end of each level we want to be able to destroy the previous spawn pool, along with all of it's sprite object prefab instances. And then LoadLevelAdditiveAsync the next scene which starts up the corresponding spawn pool.

I guess my question is, is there anything I need/can do to ensure that the atlases I no longer need are not taking up texture memory? And do you have any general experience/advice/input?

Thanks!!

« Last Edit: June 29, 2015, 07:42:39 pm by NMD »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Hi,

2D Toolkit relies on unity for memory management, so changing scene and UnloadUnusedAssets should unload stuff, but... this might not be feasible if you have a very large memory footprint - this is probably the only point where you'll need to delete stuff manually, etc.

Just make sure you don't have references to any tk2d assets / prefabs containing sprites in normal C# (not monobehaviour) objects anywhere, the object being resident could force the asset to not get unloaded, and make things a lot harder to manage.

NMD

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Hey, thanks for the info!

We are pushing memory limits but I've tried to keep it sane. Just so I know, when you say, need to delete stuff manually, what do you mean exactly?...

I started out in gamedev on c++ and in 3 years of using unity/c# I've never got too far into messing the the c# GC.  Or do you mean using UnloadAsset or Destroy to manually delete stuff?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
If you want to explicitly automatically unload a collection without changing scene you'll have to delete all references of objects using it. There's also the nasty way of going about it where you can simply find the sprite collection and UnloadTextures(). But to be more to the point - you shouldn't need to destry things unless you're keeping references to them somewhere.

The problem with unity is its nice and simple to create simple things to start, and when you start pushing it you find you need to more than make up for that initial timesaving that you had by fiddling with things you really don't care about - eg. in this case manual memory management...