How to get the texture of a tile in a Tilemap/Set

Godot Version

4.2

Question

I recently started learning Godot, i want to make a simple puzzle game where you pick up items and set them down, so far i haven’t had much issues except for recently, see instead of making every item you can interact with a node/object/scene/what-have-you i decided it would instead be faster if i just made every item a tile with properties, which indeed has made it easier, except for the fact that i want my playable character to actually be shown holding the item, which has caused some issues as i can’t seem to find the proper function.

After some research i found a function on Godot 3 that did exactly that (tile_get_texture i think it was called), but this function was apparently removed and i can’t seem to find an alternative despite how much i’ve searched, so far i’ve used the online documentation that’s integrated in the godot engine but neither TileSet, TileMap or TileData seem to have a function that specifically return a texture variable, i imagine there is a solution and i would like to know it, but if there isn’t i’ll just have to switch to using actual nodes, thanks in advance.

In godot 4 it is a little tricky. This is what you can do:

func get_cell_texture(coord:Vector2i) -> Texture:
	var source_id := _layer.get_cell_source_id(coord)
	var source:TileSetAtlasSource = tile_set.get_source(source_id) as TileSetAtlasSource
	var altas_coord := _layer.get_cell_atlas_coords(coord)
	var rect := source.get_tile_texture_region(altas_coord)
	var image:Image = source.texture.get_image()
	var tile_image := image.get_region(rect)
	return ImageTexture.create_from_image(tile_image)

_layer is the _layer contains the tile, tile_set is the tile_set property in the TileMap class. Hope it helps