How to destroy Tilemap via script

Hello, I’m creating simple 2d platformer, and generating the world “infinitely”. So I started with chunks everything went well until I found out that I don’t know how to destroy them. Every chunk is a Tilemap which is being stored in Dictionary w/ it’s Vector2 in world position. If I try to use Destroy(foregroundMap[new Vector2(x,y)]); in unity I’m getting an error :
“Can’t remove Tilemap because TilemapRenderer depends on it”
Any suggestions please ?

Don’t destroy the Tilemap; destroy the GameObject that contains the Tilemap (and the TilemapRenderer).

1 Like