Instantiation and Deletion very slow... HELP..

So I am making a game, which you can go on forever, like minecraft but 2d, and im going to use cubes. But the issue with this, is that for some reason if I am running on an update function, I am only able to generate about 30 blocks a second, when my framerate is upwords of 300… This is the same for Delete(gameobject)…

Please help - Max

Instantiate and Destroy are really slow instructions. You should use a pool of GmaeObjects instead of creating and destroying them.

Take a look at this pool tutorial.

If it does not set it clear for you, do some reserach as there are plenty of answers about GameObjects pools.

Instantiate and Destroy methods of unity are slow because of garbage collection and the alternative
that is mostly used is object pooling , that you can make an object pooling system of your own
(tutorial)or use a plugin like poolManager

For minecraft like games you should consider using a voxel generation method, instead of handling individual objects. This basically cheats by creating one huge GameObject, and modifying it as individual cubes are added and removes.

Object pooling also works