Multiple object with a tool script, consider every instance as the last one

Godot Version

4.6

Question

Hello everyone

I made an unorientated graph, that needs, to ensure neighbours go both ways, a @tool script

They all have, in their informations, an enum that will serve to identify which map they are linked to :

Like I said, each one of these has a tool script
image

I’ll summarize with the relevant infos

@tool
class_name node_map
extends Area2D

#...
@export var map_id: node_enums.maps_dictionary
#...

func _ready() -> void:
	print(map_id,":",position)

func _input(event: InputEvent) -> void:
	if event is InputEventMouseButton:
		if event.pressed && event.button_index == MouseButton.MOUSE_BUTTON_LEFT: # when left click
			load_battle()

func load_battle() -> void:
	print("We are here : ",position) # DEBUG
	var battle = load("res://GodotRes/Scenes/Tactical/battle.tscn") # C# object
	print("We are sending :",map_id) # DEBUG
	var link_scene = node_enums.get_battle_scene(map_id)
	GlobalsCS.LoadMap(link_scene) # needed to communicate with the C# code
	get_tree().change_scene_to_packed(battle)

In another file :

class_name node_enums

#...

static func get_battle_scene(battleid : maps_dictionary) -> String:
	print(battleid) # DEBUG
	match battleid:
		maps_dictionary.DefaultMap:
			return "res://GodotRes/Scenes/Maps/GenericMap.tscn" # all different maps
		maps_dictionary.ClansCapital:
			return "res://GodotRes/Scenes/Maps/ClansCapitalTmp.tscn"
		maps_dictionary.River:
			return "res://GodotRes/Scenes/Maps/river.tscn"
	return "res://GodotRes/Scenes/Maps/RoomTest.tscn"

So, when I click on the map with the “River” Map ID, on MapNode, I’m sent to the “ClansCapital” one, that is the one of MapNode3. Not only that, but in load_scene(), the print says that the node I’ve clicked on is at MapNode3 coordinates

Is this a normal bug with tools, and is there a way to go around it ? Thank you in advance

OK, I’ve found the problem :

func _input(event: InputEvent) -> void:
	if event is InputEventMouseButton:
		if event.pressed && event.button_index == MouseButton.MOUSE_BUTTON_LEFT: # when left click
			load_battle()

is called on every node

the solution ? Change it by

func _input_event(_viewport: Viewport,event: InputEvent, _shape_idx: int) -> void:
	if event is InputEventMouseButton:
		if event.pressed && event.button_index == MouseButton.MOUSE_BUTTON_LEFT:
			load_battle()

“But what is new ?” _input became _input_event. That’s it