How do save a changeble part of a TileMapLayer

Godot Version

4.7

Question

I have a world with many different scenes each with TileMapLayers (think of these scenes like levels) I want an Extra group of tiles to be loaded in if a certain condition is met. I have thought of using patterns, but there are tile on two layers with two different TileSets. Since I will be using them a lot, I also want their creation to be intuitive. How could I achieve such effect?

If you don’t need the tiles in the same 2 layers, just use 2 more TileMapLayer nodes that you can add when needed. So you’d have another 2 layers anytime you want an extra group of tiles. I think tile set scenes would be another way to do something similar.

If the extra tiles need to be in the main layers, you could have 2 scenes: one without the extras (A) and another with both (A+B). That’s a bit of a maintenance issue, though. Maybe the extras could be added to a scene inherited from the non-extras without having to maintain 2 copies of the non-extras. Inherited scenes have their own maintenance concerns, though.

Another option is to save the extras as their own scene, loop over the output of get_used_cells() in each extra layer and set_cell(...) in the main layers.