Tilemap Update Problem

I am developing a game which includes drilling of a formation. The formation is consisted of millions of tiles. So due to performance issues I decided to create the tiles on the go and delete the previous unwanted tiles.
I use a dictionary which stores all the tile positions and their state and by using tilemap.SetTile I use null to remove the tile or to the actual tile to create it. The problem is, because I have to create or remove a big area of tiles at once, when i do this my game freezes for a while. I tried to do it in another thread, but it is not allowed by Unity.
How can I cope with this issue? Is there another good technique so the game can run smoothly?
P.S.: I tried tilemap.SetTiles as well but the difference in very small. The problem is still there!

Thanks in advance!

Hi @Zachfotis,

I can think of two ways to speed up your digging.

a) You can divide your world into blocks/chunks. Each chunk has its own tilemap. If you then dig somewhere, you only need to update one chunk.

b) You can also generate everything as a mesh, which you can update in a compute shader. This will effectively be much faster, as it will run on the gpu and can be multithreaded

The best way would probably be to combine both approaches, but doing a) only would work fine as well. b) is quite a bit more complex.

Have a look at Noita’s excellent technical talk, where they had similar issues.