Godot Version
Godot4
Question
For some reason my artifact placement program has problems with garnering cell data even though the tilemaps z order is correct and the custom cell data name is correctly matched. Here is the code I appreciate any help I can get. Once again the problem is that no tile data is found no matter where I click.
extends Node2D
var groundlayer = 0
var can_place_custom_data = "can_place"
var tilepos = null
@onready var tilemap = $TileMap
func museum_get_input():
if Input.is_action_just_pressed("build"):
var mousepos = get_global_mouse_position()
tilepos = tilemap.local_to_map(mousepos)
var source_id = 0
var Atlas : Vector2i = Vector2i(6, 1)
var tileData : TileData = tilemap.get_cell_tile_data(groundlayer, tilepos)
if tileData:
var can_place_artifact = tileData.get_custom_data(can_place_custom_data)
if can_place_artifact:
global.remove_item("Artifact", "Figural Bowl")
var artifact_sprite = Sprite2D.new() # Create a new sprite node
artifact_sprite.texture = "res://Art/Figural Bowl.png"
artifact_sprite.position = tilepos # Set the position of the sprite to the tile position
get_node("Build").add_child(artifact_sprite) # Add the sprite as a child to the scene
else:
print("can't place an artifact")
else:
print("no tile data")```