- Home /
Releasing assets loaded from asset bundle
When I tried to destroy an Object loaded from an asset bundle, I get this error message :
"Destroying assets is not permitted to avoid data loss."
If I used DestroyImmediate( obj, true ), Unity crashes.
The code is basically :
Texture2D texture = assetBundle.Load( "textureName" );
assetBundle.Unload( false );
Object.Destroy( texture );
In my project, it would allow me to load assets dynamically and destroy them when I don't need them anymore. In my understanding, the loaded texture is not an asset, it's a bunch of bytes uncompressed from an asset. So I should able to release them to free up memory.
I know there is the AssetBundle.Unload( true ) method, but I need the asset bundle in memory and AFAIK, the whole content of the asset bundle is kept in memory.
Is there a way to get this work ?
hey @Ludovic, did this bug get solved for you? Could you please send me a link to the bug report you created?
Answer by jonas-echterhoff · Jan 17, 2011 at 07:55 PM
DestroyImmediate should in theory do what you want. It certainly should not crash. Can you submit a bug report so we can take a look?
Edit: I had a look at the bug report. Crashing here is a bug and we'll have it fixed. But, to actually solve your problem at hand, what you should do is just to lose all references to the Texture, and then call Resources.UnloadUnusedAssets().
Has this been solved? I have the same problem. The standalone player crashes when I try to destroy the assets loaded from an asset bundle after I unloaded the asset bundle using Unload(false). Please help!!
Would love to know the answer to this. I've been looking for answers to similar questions ( http://answers.unity3d.com/questions/258445/why-does-unity-crash-when-i-stop-playing-an-asset.html?sort=oldest ) . I tried yielding while waiting for the next frame to load. This got my scene to show up, but it crashes the editor the second I hit "unpause" — I assume this is due to the Play button in the Editor automatically calling DestroyImmediately on the objects? It has been too problematic to work with and I haven't gotten any definitive answers from anyone yet, so unfortunately my $$anonymous$$m will have to pass on asset bundle loaded scenes as we cannot even test our game in the Editor. :( :( :(
Has anyone else figured out how to do this????
Your answer
Follow this Question
Related Questions
Webplayer crashes on Chrome, but not on any other browser. Any way to avoid ? 1 Answer
How StreamedSceneAssetBundle differ from AssetBundle in terms of scripting? 0 Answers
Keeping assetbundles in memory vs always loading from cache 1 Answer
How to have 2 sets of textures and make sure only one is loaded? 0 Answers
Are Texture2Ds in a Resources folder always loaded in memory? 1 Answer