Unloading Spritesheets loaded from asset bundle?

Hi Everyone, there’s a spritesheet that’s resident in memory for our whole game. I’m looking at how we can unload it completely and free up its texture memory when it’s not needed. The way we’re loading it is via an AssetBundleRequest:

        var request = ab.LoadAssetWithSubAssetsAsync<T>(path);
        yield return request;
        var t = request.allAssets as T[];
        callback(t);

‘t’ is now a Sprite[ ] that’s passed back up into game code for storage and lookups.

How would one forcibly unload the whole spritesheet in this case? By the time we’re done with the spritesheet, the AssetBundleRequest is long gone and we only have references to the individual sprites at this point. Also, the bundles in question contain assets that are used for other purposes, and those shouldn’t be unloaded when it’s time to unload this spritesheet.

Thanks in advance,
Jeff

FYI our spritesheet is a .PNG file with some entries in the .meta file that describes the location/size of each sub sprite. It’s generated by a tool called TexturePacker. It’s not a SpriteAtlas asset

ab.Unload(true)

This unloads all loaded objects from that specific bundle and is the recommended way to clean up. Depending on how you have packed your assets into bundles, you might need to shuffle that around a bit / break it up into more bundles to make it easier to load / unload incrementally.

1 Like

That’s what I was gonna ask next. If making one bundle for each spritesheet is the only way to unload them in isolation then this is what we’ll do. We have the technology!