[Godot 4] TileMap "get_custom_data_by_layer_id" is not using layer id

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By gon123

I cannot spot my error, I have started thinking there is a bug with the function “get_custom_data_by_layer_id()” from “TileData”.

I have the following code where I first get the cell data and then I get the custom data with the layer of that cell, but custom data is always null except for layer id “1”:.

for layer in layers:
	var data = get_cell_tile_data(layer, coords)
	if data != null:
		var result = {
			"coords": coords,
			"layer": layer,
			"data": data.get_custom_data_by_layer_id(layer)}
		print(result)
		for layer1 in layers:
			print("Layer: ", layer1, ". Data: ", data.get_custom_data_by_layer_id(layer1))
		return result

This will always print:

{ "coords": (3, 3), "layer": 2, "data": <null> }
Layer: 3. Data: <null>
Layer: 2. Data: <null>
Layer: 1. Data: <null>
Layer: 0. Data: 0

I’ve been searching for a way to set the custom data selecting the layer, but I couldn’t find anything.
I haven’t found neither any info about this bug.

Thank you!

:bust_in_silhouette: Reply From: gon123

Ok, I think I got it, there is no problem with godot, just a bad naming in my opinion.

In “get_custom_data_by_layer_id(layer_id)” or “get_custom_data_by_layer_id(layer_name)”, the layer is not related with the tilemap layers but with the array of custom data properties you can configure.

It was my fault, I misunderstood it, I think they should change the naming there haha