Hello Guest

Author Topic: Multiple collections for animations and reloading  (Read 3144 times)

Dreamkind

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Multiple collections for animations and reloading
« on: November 20, 2013, 12:44:54 am »
Hi,
I am working on a rather huge project with a lot of art. And when I say a lot of art I mean a lot. At the end of each scene we play one of 6 different ending animations. When we put all of the different animations into 1 Collection it crashes when it tries to load it due to running out of memory. The solution that we found was each clip inside the animation would have its own collection thus we only have to load 1 collection into memory at a time.

These are being created dynamically by loading the animation library via resources.load, then creating a game object, attaching a sprite component, adding an animator component, then setting the library of the component. When the sprite needs to show up we play the correct clip, which causes a pause while it loads the collection that that clip needs.

When leaving the scene, we switch to a loading scene which basically has nothing in it except a background and a few graphics from an unrelated sprite collection. For some reason if we go back out to the main menu, then back into the game the sprite collection that the animation uses is no longer in memory, but if we go from the loading screen back into the game, the previous collection is still in memory, thus when another ending animation is played it loads that collection into memory as well.

We are on unity 4.3 and 2d toolkit version 2.3.0.

Is there something that is causing sprite collection data to not be cleaned up correctly? When we disable the animated sprite the level works just fine and doesn't have any extra data on subsequent play throughs of the same level.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Multiple collections for animations and reloading
« Reply #1 on: November 20, 2013, 10:03:33 am »
Have you tried calling UnloadUnusedAssets from the empty scene?

Dreamkind

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Multiple collections for animations and reloading
« Reply #2 on: November 20, 2013, 03:23:36 pm »
Yes. We tried calling Unload Unused Assets, and waiting for the Action that it starts to finish. We tried manually deleting the object from the old scene before loading into the loading scene. Our loading scene is not 100% empty because the app allows the user to change the background for the app, which is a sprite that is not destroyed on load. The only collections in use during the loading screen are the backgrounds collection and the loading screen collection.

We did find a solution that looks like it works.

Code: [Select]
// Unload unused assets.
tk2dSpriteCollectionData[] spriteCollections = Resources.FindObjectsOfTypeAll<tk2dSpriteCollectionData>();
Shared.Debug.Log("Sprite colleciton count: " + spriteCollections.Length);

if (_retainedCollectionNames != null) {

foreach (tk2dSpriteCollectionData collection in spriteCollections) {

string collectionName = collection.inst.assetName;

if (!string.IsNullOrEmpty(collectionName)) {

if (!_retainedCollectionNames.Contains(collectionName)) {

Shared.Debug.Log("Unloading collection: " + collectionName);
collection.ResetPlatformData();
}
}
}
}

_loadingOperation = Application.LoadLevelAsync(_nextLevelName);

Basically we have a lit of collections that we know we 100% want to retain in between the loading screen and we free up any non retained ones. It just looks like unity has some sort of "smart" resource management that tries to hold on to stuff across a couple of scene loads.