Hello there,
I am new to Godot (as so many people) and I would like to build a little board game using 3D planes as tiles. I am experiencing a (to me) confusing behavior with click event handling. I attached the project as zip file (boardgame-godot.zip).
I have two scenes. The main scene and a tile scene. Each tile should get some individual properties and emit a custom tile_clicked signal on the mouse click input event. The tile_clicked signal (of each tile instance) is than connected to the Main.gd script and should change the color of the material.
Now the confusing bahavior. When I click a tile it sometimes changes the color and sometimes not. I printed the instance_ids and names for debugging purposes and realized that each tile seems to have two instance_ids ?? The color change only happens when one of the two instance_ids (tiles) is clicked.
As further investigation I printed the instance_ids and names in the Main node inside the _ready() function and for some reason each print occours two times with different instance_ids but equal Node names.
Can someone explain to me what exactly happens here? I assumed that each instanced tile exits one time and the instance_id might be a vehicle to obtain objects reliably (via instance_from_id()).
Here some screenshots of my setup

Here are the scripts:
Main.gd
extends Spatial
# Called when the node enters the scene tree for the first time.
func _ready():
print("_ready Board: " + str($Board.get_instance_id()))
print("_ready Tile: " + str($Board/Tile.get_instance_id()))
print("_ready Tile2: " + str($Board/Tile2.get_instance_id()))
print("_ready Tile3: " + str($Board/Tile3.get_instance_id()))
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _on_Tile_clicked(tile: Tile):
print("tile (name: " + tile.get_name() + ", instance_id: " + str(tile.get_instance_id()) + ") clicked: " + str(tile.pos_x) + "," + str(tile.pos_y))
tile.highlight()
Tile.gd
extends StaticBody
class_name Tile
export(int, 1, 9) var pos_x
export(int, 1, 5) var pos_y
signal tile_clicked
# Called when the node enters the scene tree for the first time.
func _ready():
connect("input_event", self, "_on_Input")
func _on_Input(
camera: Node,
event: InputEvent,
click_position: Vector3,
click_normal: Vector3 ,
shape_idx: int) -> void:
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and event.pressed:
emit_signal("tile_clicked", self)
func highlight():
$MeshInstance.get_surface_material(0).albedo_color = Color(1, 0, 0)
func lowlight():
$MeshInstance.get_surface_material(0).albedo_color = Color(0, 1, 0)