Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Disable Mesh Filter or Completly Remove ?

Discussion in 'Editor & General Support' started by neutralh, Sep 19, 2014.

  1. neutralh

    neutralh

    Joined:
    Aug 18, 2014
    Posts:
    6
    I am working on a large scale game which uses tiled Meshes instead of terrain, i am trying to find a way to improve performance by removing far away meshes and objects but i am not sure what to do.

    what is the difference between destroying the object with the mesh and simply disabling the mesh filter.
    what does disabling the mesh filter / renderer do ? (leave it in memory, but doesnt process it ?)
    is it better to disable the entire gameobject instead of deleting it ? (with SetActive = false)
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    If you are not running into memory problems you should just disable the game-object or the mesh render.
    Destroying means work for your garbage collector -> Work for the CPU that can cause lag.
     
  3. neutralh

    neutralh

    Joined:
    Aug 18, 2014
    Posts:
    6
    yes but what does disabling do exactly, because all of the people making tiled terrains that i found dont use "disable" they use dynamic loading techniques.
     
  4. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    disabling a game object shuts down the updates and other call backs on the game object and its components.
    So you Update and rendering is disabled but all the stuff is still in memory.
    If you have a massive terrain you have a memory problem.
    So the most massive terrain projects instantiate the terrain parts if its needed to keep the terrain out of the memory as long as possible.
    Functions like Application.LoadLevelAdditiveAsync can also be used to load another "Terrain Scene" later on.
    If you have enough CPU capacity that the cleanup and reinterpretation is not your concern for lag then you should destroy the terrain rather disabling it.

    If you destroy the terrain and the user has any way to change anything that is happening on the terrain (like digging hole or removing objects form the terrain) you have to keep track of it if you like to destroy the terrain so you can reconstruct the state of the terrain if its re Instantiated.
     
    neutralh likes this.
  5. 10HPLeft

    10HPLeft

    Joined:
    Mar 23, 2014
    Posts:
    3
    I believe setting `enabled = false` on a `MeshFilter` will tell Unity to remove the mesh data from GPU memory, triggering a reupload of ALL GPU memory (or at least the VBOs). That can be extremely costly and cause a frame hitch, so you might consider simply disabling the `MeshRenderer` if you can afford the memory costs, or disable/destroy `MeshFilter` during a transition.

    That's of course on top of the previous descussion. Destroying/Removing the component will at LEAST trigger the same problem, and destroying or setting the `GameObject` to inactive will incur all the same costs but for all components on said GO.

    Destroy on any of those will also incur the garbage collection costs mentioned by fffMalzbier.

    This is extraordinarily late, but still relevant 4 years later.
     
    Last edited: Oct 2, 2018