Tilemap Chunkloading Efficiency

Godot Version

4.2.1 Stable


Maps in my game are procedurally generated and large, so they are loaded in chunks. Everything on the map is 2d blocks, like Terraria, so they are made up of tilemaps.

Currently I have it implemented where each chunk loaded is its own tilemap node, and I give it data and it changes that specific tilemap node.

I was wondering though if it would be more efficient to have one large tile map, and every chunk is just a piece of data that I load “into” the main tilemap of the map once it is in distance, rather than new tilemap nodes. And inversely just set those tiles to blank/air when the player is out of distance.

My guess is that separate tilemaps are more efficient, as when I was reading through the documentation for tilemaps it said that every update to the tilemap is costly. I assume many smaller tilemaps that update as needed would be less costly than one large map that has to be updated for any change anywhere, but also I’m not an expert on the internal workings of either tilemaps nor Godot, so here I am.


Sure it would be more efficient, the question is “does it actually matter”, which no it probably doesn’t matter enough to spend time building it that way. The average processor won’t even hiccup so it’s a tradeoff of if you are having huge enough data (unlikely). It also depends on how many tiles on your screen at once, if the player can zoom out very far then that may make a difference, altho I suspect then the optimization won’t help much as it will be a different bottleneck rendering 10000’s of tiles

edit: that said, it’s probably not that hard to do, a good learning experience, and bring some features that you may need from 1 tilemap… or even have it as an option in code you can use

Are you saying one larger tilemap node is more efficient or many smaller tilemap nodes would be more efficient?

Also regarding what you said about performance, likely you’re right. Though like you said, it would be good for learning more about Godot in general. Beyond that, I also just enjoy making all my code as efficient as I can. Alongside that, in the game, large and small updates to the tilemap will be commonplace, so I just think it’s a good idea to make something that happens a lot as efficient as possible.

The data/code will be mostly the same anyways, it shouldn’t be too hard of an undertaking either way that I do it. If each chunk is its own tilemap, when changes are made to the tilemap, I just need to check if the coordinates it is trying to edit are out of the bounds of that chunks distance with some simple math, and if it is, send it over to the proper chunk (e.g. if an explosion happens and chunk 4 tries to edit its tilemap -1, 0 tile, it instead tells the chunk to its left to edit tile 99, 0 (for chunks of 100x100 size).

It will be easier for you if you combine it into one TileMap (in the example you are giving of the explosion). I usually use at least 4-8 overlaid TileMaps per level, and then I may have dozens of rooms each with 4+ TileMaps. I haven’t had any noticeable slowdowns.

Some relevant comments:



Is there any reason to use multiple Tilemaps rather than just multiple layers in a single Tilemap node? I can’t seem to find any reason to do so, all I’ve found is that older versions didn’t have multiple layers per Tilemap.

Also, I had another question, but it deviates from this topic significantly enough I made a new topic. I only mention it here as my new question somewhat stems from the same topic as this. Link is here if you’d like to view it - Setting Tiles During Runtime

I asked a similar question about tile sets a while back and got a good answer, not exactly an answer to your question but definitely relevant:

Yes, use multiple TileMap nodes. Your intuition is correct. I find 64x64 or 128x128 are good chunk sizes for most uses.
For the navigation, you can use a single square covering each chunk and bake that after the tiles are ready. I’ve done it before and it works better with smaller map sections because of the interconnection overhead when baking. If you find moving around is too slow for realtime, just make the navigation shapes smaller. This doesn’t change the final result, only how much work is done in each shape, which for tiles it’s often unnecessary ray checks anyway.
I don’t have much more to say, just remember that different parts of the TileMap system can be independent of each other. There’s a lot you can do with that, but for basic use you’re on the right track.