Asset Bundle load/unload problems

Hi everybody,

I’m having some trouble with Asset Bundles here. I have a script that runs in both the editor and during gameplay, and it is loading an array of 3x3 WWW objects, each one loading an asset bundle. Loading is not a problem, it is working perfectly, my problem is unloading it.
I tried to load it, display the object the asset bundle contained, and keep it in memory until time to unload it, but this messed up when I went from editor to play, as for some reason my object loses reference in the array as soon as I press play, and then Unity complains my asset bundle is already loaded, and WWW fails.
Because of that, I thought, why not load the asset bundle, get the object, and then destroy it right away? I tried this, and this worked nicely in the editor, but as soon as I press play, things get messed up with my 1st load, not loading my terrainData object. I thought, okay, as soon as I’m destroying the asset bundle and www object, it is destroying my TerrainData as well.
Then I thought, okay, if it is being destroyed, I’ll clone it with Instantiate() before destroying it, then there’ll be no reference, and it indeed does clone my terrainData, but destroying all my splatmaps, trees and details.

What I need to know, is there any way to load an asset bundle with WWW, get a terrainData from it (assume it is the only asset in the bundle), destroy it right after loading and STILL get the terrainData, working both in runtime and editor? (sorry I don’t have my code here, at work right now)

Well, seems Unity doesn’t provide any way to keep track of loaded/unloaded asset bundles, in Editor or in Runtime… What I had to do is to make this control myself, and also deal with it on the script Awake and in its destruction, so when I switch off to either mode, the asset bundles get destroyed correctly. Then, I don’t get any conflicts with Unity telling me I am loading an already loaded asset. Cloning the asset before destruction seemed useless and also behaved unpredictably.

I had a similar problem. My editor script was loading an asset bundle. The second time I ran the script, it told me that the asset bundle was already loaded, so cannot load again. I fixed this by calling this:

assetBundle.Unload(false);

This will make the asset bundle unload its data from runtime memory, but scene instances will remain in tact. Also, if you decide to load that asset bundle again later, unity will not complain because it is not considered in memory. If you call assetBundle.Unload(true), I think all of your scene instances will be destroyed.