Search Unity

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

Discussion in 'Scripting' started by mahdiii, Aug 20, 2017.

  1. mahdiii

    mahdiii

    Joined:
    Oct 30, 2014
    Posts:
    856
    Hi all
    I would like to unload inactive objects from Ram and somewhere load them again.
    Thx in advance
     
  2. joshcantcode

    joshcantcode

    Joined:
    Aug 20, 2017
    Posts:
    6
    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.
     
  3. tonemcbride

    tonemcbride

    Joined:
    Sep 7, 2010
    Posts:
    1,084
  4. mahdiii

    mahdiii

    Joined:
    Oct 30, 2014
    Posts:
    856
  5. tonemcbride

    tonemcbride

    Joined:
    Sep 7, 2010
    Posts:
    1,084
    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 (http://answers.unity3d.com/questions/366783/how-to-remove-textures-from-memory-downloaded-duri.html)
     
    mahdiii likes this.
  6. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    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.
     
    mahdiii likes this.