Hello Guest

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - undersan

Pages: [1]
Support / Re: Unload Textures
« on: April 16, 2014, 08:37:22 pm »
I thought I'd revive this thread to talk about unloading textures from asset bundles.  I'm on Unity 4.3.4 and I test on Mac and iOS.

>Referencing the asset again should be enough to trigger Unity to load it in again
This is correct if the asset is from the Resources folder.

For a texture from an asset bundle, the behavior I see is that all references to that texture are set to null the instant you call Resources.UnloadAsset.  It's up to you to manually reload the texture and fix up references to the reloaded texture.  Here's what I'm doing:

Code: [Select]

// texture is now unloaded and related sprites can't be used (they will display as garbage on Mac and iOS)

// later...

// For now, I've hardcoded the texture I care about. In the future,
// I need a system to know the path for a collection's texture.
string path = "Units/1m_citizen/atlas0.png";

Texture reloadedTexture = assetBundle.Load(path, typeof(Texture)) as Texture;

// manually fix up collection's references to this texture
myCollectionData.materials[0].mainTexture = reloadedTexture;
myCollectionData.textures[0] = reloadedTexture;

So now, given that I need to manually reload collection textures, I find myself leaning towards a refcounting solution like jmcguirk proposed in his initial post.

Any thoughts on this?

Pages: [1]