_unhandled_input stoped work after added child node2d

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By azusdex

Hi, after added object (node2d) to main scene _unhandled_input stopped work on click in the object. In other place of scene this event listener work fine.
For example - main scene “Game” and child scene “Map”. Firstly, I click to “Game” scene to add new child “Tower” into the “Map”. I can click to other place - this method work. If I click to “Tower” - this not work. What I don’t understand here?

This event method:

# init 
func _ready():
    map_node = get_node("Map")
    towers_node = map_node.get_node("Towers")

func _unhandled_input(event: InputEvent):
    if event.is_action_released('ui_click'):
	    print("click")
	    var path_map = map_node.get_node("Road")
	    var current_tile = 
            path_map.world_to_map(path_map.to_local(get_global_mouse_position()))
	    var position = path_map.to_global(path_map.map_to_world(current_tile))
	if path_map.get_cellv(current_tile) == -1:
		_build_tower("Archer", position)
	else:
		print("Can't build here")

This method to add object:

func _build_tower(type: String, position: Vector2) -> void:
    var tower = load("res://Scenes/Towers/" + type + ".tscn").instance()
    tower.position = position
    towers_node.add_child(tower, true)

Thanks

Does the node2d have anything that would catch the input?

exuin | 2023-02-28 05:34

Thanks for the tip

azusdex | 2023-02-28 15:46

:bust_in_silhouette: Reply From: azusdex

I found problem - new scene child has this structure:
→ Node2D
→ Control
→ Sprite
After remove Control, _unhandled_input - works fine.

It’s the Control node that will get you every time. :smiley:

Ertain | 2023-02-28 18:17