# How to remove an element from the scene while keeping it in array?

I combined cube meshes to make a big one. I stored the info of every cube in an array within a list of chunk. Now i want to delete the cubes in the scene to only keep the combined result, but without deleting the elements in the array. After combining meshes, i want to be able do destroy cube from it. So i want to keep the info so when i click the mesh, i get the position of the cube that would be there and check if it matches wit ha cube from the array. If it does, i want to remove it from the array and regenerate the mesh without that deleted cube.

How would I do that ?

• Why do you want to keep references to game objects in an array when those don't exist in the scene anymore? Do you need some specific information about them? Then it might be better to just store a copy of that information. – Philipp Jun 17 '19 at 16:02
• after combining meshes, i want to be able do destroy cube from it. So i want to keep the info so when i click the mesh, i get the position of the cube that would be there and check if it matches wit ha cube from the array. If it does, i want to remove it from the array and regenerate the mesh without that deleted cube – Samuel Fyckes Jun 17 '19 at 17:29
• Your object that describes the voxel should not be the scene object that represents the voxel in the world. Use a lighter-weight datastructure for that part, completely unrelated to your scene hierarchy. – DMGregory Jun 17 '19 at 17:45
• Waht does that mean ? what do you mean by " your object that represent the voxel", "lighter weight datastructure" – Samuel Fyckes Jun 17 '19 at 17:52

If you want to keep the whole cube game object around after merging the meshes so you can restore them later, then it would be better to deactivate it with gameObject.SetActive(false) instead of destroying it. That way it stays in memory as it is and you can later reactivate it with SetActive(false).
However, for your particular use-case, that might be overkill. You would keep a lot of data about the gameObject in memory which you don't need and end up wasting a lot of RAM. All you really need to store are the coordinates of the cube within the larger merged mesh. So it would be better to define a struct which holds only the data you need about a merged cube and create an array of those struct's which you store on a component of the merged mesh.