How to load and unload inactive objects(textures,musics,meshes,...) to/from RAM?

Hi all
I would like to unload inactive objects from Ram and somewhere load them again.
Thx in advance

I’m not sure Unity is capable of editing your VRAM through code, but if I were to guess, simply unloading them and removing them from the scene would remove them from the VRAM.

You could try Unity - Scripting API: Resources.UnloadUnusedAssets or GC.Collect

thank you. so we can unload only resources? (that load using Resources.load?)

I’m not certain, it looks like it unloads anything that isn’t currently referenced in the scene (or by any components in your scene) but perhaps it’s just for resources.load objects as you mentioned. You generally don’t need to call it manually anyway as Unity will automatically call it when it gets a message from the host operating system indicating that it’s low in memory. (for example, on iOS).

p.s. You can also destroy textures manually (How to Remove Textures from Memory (Downloaded During Play) - Questions & Answers - Unity Discussions)

1 Like

Unity will unload anything that’s not in the current scene automatically when you change scenes. But you can’t force it to unload something that is in the current scene but just disabled. It still needs to keep all the data in memory in case you enable it again. You can call Destroy() to destroy objects, but then they’re gone and would need to be re-created when you need them.

1 Like