How do I actually delete an asset from memory?

Hey, all,

So having read this very informative thread: http://forum.unity3d.com/threads/97690-The-Ins-and-Outs-of-Audio-Memory-in-Unity, i realized that a lot of my audio code was set up to cause memory leaks.

I’ve since changed the array-based system to a List, so that in the “OnDestroy” function just calls clear() on it, which should destroy the assets in question. That bit is fine.

What I do have an issue with, however, is objects which exist in my scenes which have had sound clips dragged to them from the editor. Calling “Destroy” on them gives me the Destroying assets is not permitted to avoid data loss message.

So how do I destroy them?

Cheers,

SB

I also have to ask - why does “Destroy” try to destroy the physical asset? Why doesn’t it just destroy the reference? I struggle to think of a time when I’d want to destroy - permanently - an asset that shipped with the game, and even if I did, shouldn’t there be a separate command for that?

If you call Destroy() on assets then what else would you expect than destroying them ;)?! I only know this message when writing editor scripts… At runtime I never had it. Use DestroyImmediate(obj, true) instead but beaware of that it might now delete assets. You can’t permanently delete an asset shipped with the game like this (at runtime everything is in an “don’t remember” mode as you may have noticed). But you can delete an asset in the editor…