Godot Version
4.3 rc2
Question
I am working on a small action tower defense game and I want to create a HUD element that allows the player to select different turrets to place but the problem is that the function connected to the gui_input
signal never gets called.
I have a scene for the panel containers at the bottom that looks like this
class_name TowerPanelContainer
extends PanelContainer
@onready var _label: Label = $VBoxContainer/CenterContainer/Label
@onready var _texture_rect: TextureRect = $VBoxContainer/TextureRect
var text: String
var texture: Texture2D
func _ready() -> void:
if not text.is_empty():
_label.text = text
if texture:
_texture_rect.texture = texture
This scene is instantiated like so
# in HUD.gd
for turret_data: Dictionary in _turret_data_aray:
var tower_panel_container := TOWER_PANEL_CONTAINER.instantiate() as TowerPanelContainer
tower_panel_container.text = turret_data["name"]
# This signal connection used to work and I don't know why it's broken now
tower_panel_container.gui_input.connect(func(event: InputEvent) -> void:
if event.is_action_pressed("left_click"):
selected_tower_scene = turret_data["scene"]
)
_tower_panel_containers.add_child(tower_panel_container)
The lambda function connected to the gui_input
signal does not work. It seems that the signal is never fired. How can I fix this issue? I think it’s because of some wrong mouse_filter
in the panel container or another HUD element but I can’t figure out a combination to make this work.
P.S.: This is what the remote scene tree looks like