Fast Deletion of 2D Tilemap Colliders

Hiya!

I’m currently working on a procedurally generated 2D asteroids-type game and at the moment I’m working on the chunk loading and unloading system. Each chunk is made up of a Tilemap and a Tilemap Collider.

So far I’ve programmed it and it works pretty well, the game runs well when no chunks are being unloaded. However when I do unload chunks the fps dropped quite a lot, from around 1000-2000 to 100-300. This is mostly because of the 2D physics engine destroying the tile colliders.

100fps sounds pretty good, but currently the game is only a ship and chunks, I’m worried that it won’t be able to run well on worse PCs, as mine is between decent and pretty good.

Sorry I haven’t provided any images of the game! I’m currently away from my computer

I was wondering if anyone could suggest a way to optimise it, or should I be expect tile colliders to take time to delete? Sorry if I didn’t explain it very well.

Thanks lots! :slight_smile:

Can’t you reuse them? Essentially it’s a good idea to pool objects instead of creating and destroying. Obviously I have no idea what and how you create these chunks, so I’m just leave it here. If you can reuse the elements when you load the next (or the next after that) chunk, do not destroy them, hide them, configure them according to the new requirements and reactivate them.

1 Like

Oh wow, you’re totally right. I really should thought to try that! I’ll make sure to try that out tomorrow, thanks loads.

1 Like

In scenarios like this, it’s often the case that it’s not the “TilemapCollider2D” deleting tiles that takes the time (that should be pretty quick) but it’s the fact that a “CompositeCollider2D” is being used too. When a tile is deleted, it has to recalculate the whole tilemap (there’s no shortcut it’s able to take) to produce a new composite. While it is fairly quick, as the number of tile shapes goes up, so does the time to calculate. The profiler should tell you where the time is actually being spent specifically.

2 Likes