Describe the project you are working on
A 2D platformer character that checks the tile under it for custom data, for things like having different footstep noises.
Describe the problem or limitation you are having in your project
The way to get a custom data layer from a tile I'm currently touching is by doing this (the final line is the most relevant):
for i in range(get_slide_collision_count()):
var slide_collision: KinematicCollision2D = get_slide_collision(i)
if slide_collision.get_collider() is TileMapLayer:
var tilemaplayer: TileMapLayer = slide_collision.get_collider()
var tile_coords: Vector2i = tilemaplayer.get_coords_for_body_rid(slide_collision.get_collider_rid())
var tile_data: TileData = tilemaplayer.get_cell_tile_data(tile_coords)
var is_metal_tile: Variant = tile_data.get_custom_data("is_metal_floor")
There's one major problem with this: tile_data.get_custom_data("is_metal_floor") throws an error if the custom data layer doesn't exist on the current tile. The problem is that there's no way to check via the TileData if a data layer exists on it or not, which is weird and unintuitive.

This becomes confusing for people trying to just fetch custom tile data without causing errors. See: https://forum.godotengine.org/t/can-you-determine-if-a-custom-data-layer-exists-for-a-tilemaplayer/85891
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Add a function has_custom_data(layer_name: String) which would allow me to check if it exists before trying to get it.
Alternatively, maybe the function shouldn't cause an error in the first place and just let me check if it's null or not.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
...
if tile_data.has_custom_data("is_metal_floor"):
if tile_data.get_custom_data("is_metal_floor") == true:
[do stuff without getting errors]
If this enhancement will not be used often, can it be worked around with a few lines of script?
Yes, but you would need to check if the data layer exists in the TileSet first rather than TileData, which is cumbersome and probably not always accessible. If TileData can get the custom data layer, it should also tell me whether it exists or not.
See: https://forum.godotengine.org/t/can-you-determine-if-a-custom-data-layer-exists-for-a-tilemaplayer/85891/5
Is there a reason why this should be core and not an add-on in the asset library?
It's core functionality.
Describe the project you are working on
A 2D platformer character that checks the tile under it for custom data, for things like having different footstep noises.
Describe the problem or limitation you are having in your project
The way to get a custom data layer from a tile I'm currently touching is by doing this (the final line is the most relevant):
There's one major problem with this:
tile_data.get_custom_data("is_metal_floor")throws an error if the custom data layer doesn't exist on the current tile. The problem is that there's no way to check via the TileData if a data layer exists on it or not, which is weird and unintuitive.This becomes confusing for people trying to just fetch custom tile data without causing errors. See: https://forum.godotengine.org/t/can-you-determine-if-a-custom-data-layer-exists-for-a-tilemaplayer/85891
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Add a function
has_custom_data(layer_name: String)which would allow me to check if it exists before trying to get it.Alternatively, maybe the function shouldn't cause an error in the first place and just let me check if it's null or not.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
If this enhancement will not be used often, can it be worked around with a few lines of script?
Yes, but you would need to check if the data layer exists in the TileSet first rather than TileData, which is cumbersome and probably not always accessible. If TileData can get the custom data layer, it should also tell me whether it exists or not.
See: https://forum.godotengine.org/t/can-you-determine-if-a-custom-data-layer-exists-for-a-tilemaplayer/85891/5
Is there a reason why this should be core and not an add-on in the asset library?
It's core functionality.