You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In chunk.cs CreateMesh, before assigning the new mesh to meshFIlter (meshFilter.mesh = mesh;), we have to destroy the old mesh (Object.Destroy(meshFilter.sharedMesh);); otherwise we will face memory leak. The leak is disastrous especially when you put lots of blocks in game (>1000).
The text was updated successfully, but these errors were encountered:
Can you explain why? Why do we have to destroy the shared mesh and why does it cause a leak?
Sorry if I'm answering late. Unused mesh or material will not be collected by the garbage collector, So when you are replacing the old mesh with the new one, you have to destroy the old one yourself. In order to access the old mesh, you have to use meshFilter.sharedMesh instead of meshFilter.mesh because the latter will give a new instance of the mesh and you don't want that.
In chunk.cs CreateMesh, before assigning the new mesh to meshFIlter (
meshFilter.mesh = mesh;
), we have to destroy the old mesh (Object.Destroy(meshFilter.sharedMesh);
); otherwise we will face memory leak. The leak is disastrous especially when you put lots of blocks in game (>1000).The text was updated successfully, but these errors were encountered: