Is it possible to get the id of a layer of a TileMap by his name alone ? Doing by id is not ideal since I may change the layer ordering at a certain point, and the ids will also change, but the tiles will remain. So if a decoration layer is swapped (in layers) with a effect position the effects will remove the tiles.

We have the function void set_layer_name(layer: int, name: String) and get_layer but those are not really useful currently

I did this as a little hack, since I don't add/move layers:

var layers_dict = {}

func _ready():
	set_layers()

func set_layers():
	for layer_id in range(self.get_layers_count()):
		var layer_name = self.get_layer_name(layer_id)
		layers_dict[layer_name] = layer_id

But this is just a little hack, am I missing something or should it be implemented in godot ?

I just looked at the code in the master branch of Godot and layers are defined like this:

LocalVector<TileMapLayer> layers;

struct TileMapLayer {
    String name;
    // other things
}

So the code structure does not allow for O(1) name to id, but it would be easy with little changes

I think that would be usefu for TileMap users to have this option. Am I fooled ? Is a little pull request required ?

If you think you have a solid idea on how to do this and think you have a good justification for it then step 1 would be to open a proposal/issue on the proposals tracker. That is, before you go on to commit any of your time toward making a pull request. That way further discussion on merits and implementation details can happen first.

You are free of course to just invest the time and make a pull request as is, but no guarantees if and when it would get in. @Calinou can correct me if I'm wrong on any of this.