x


How can I unload a single resource?

I can use Resources.Load(path) to load a single resource file. How can I unload it?

  • Object.Destroy says I can't destroy an asset

  • Object.DestroyImmediate destroys the resource, and the underlying asset, and requires me to re-import in the editor (surprise!)

  • Resources.UnloadUnusedAssets doesn't let me pick which resource to unload

Should I just use UnloadUnusedAssets anyway?

more ▼

asked Apr 26 '10 at 04:40 AM

yoyo gravatar image

yoyo
6.4k 25 39 84

Resources.UnloadUnusedAssets seems to be a frame rate killer, so I'd like to avoid if I can.

Apr 26 '10 at 05:01 AM yoyo

And yes, I believe AssetBundles would solve the problem, but I'm using the free edition of Unity, so AssetBundles are not available to me.

Apr 26 '10 at 05:02 AM yoyo
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

A new method has been added in Unity 3.5.2 that should do what you are after:

Resources.UnloadAsset(Object asset);
more ▼

answered May 16 '12 at 06:43 AM

Datael gravatar image

Datael
555 2 5

Great! Didn't know that, thanks

Jul 17 '12 at 01:25 PM Izitmee

Except it complains that it can't be used on a GameObject :(

Oct 26 '12 at 04:34 AM yoyo
(comments are locked)
10|3000 characters needed characters left
more ▼

answered Apr 26 '10 at 09:57 AM

StephanK gravatar image

StephanK
6k 39 53 93

Thanks for the link. The thread suggests using Destroy to unload assets ("You need to Destroy() assets and remove all references to them in order to clean the memory after loading them."), but as I mentioned above this technique doesn't work. I suspect it would be the right approach if I was procedurally generating the assets, but for my use case it doesn't work.

Apr 27 '10 at 02:06 AM yoyo
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x417
x242
x217

asked: Apr 26 '10 at 04:40 AM

Seen: 6061 times

Last Updated: Oct 26 '12 at 04:34 AM