Invalid access to property or key 'pressed' on a base object of type 'Control'.

Godot Version

4.6.1

Question

i have no idea whats wrong, its been working fine a moment ago and now apparently its not, any idea what might be the problem?

class_name Menu extends Control

signal button_focused(button: BaseButton)
signal button_pressed(button: BaseButton)

var index: int = 0

func get_buttons() -> Array:
	return get_children()

func _ready() -> void:
	var _class: String = get_class()
		
	for button in get_buttons():
		button.focus_exited.connect(_on_Button_focus_exited.bind(button))
		button.focus_entered.connect(_on_Button_focused.bind(button))
		button.pressed.connect(_on_Button_pressed.bind(button)) #heres the problem
	
func connect_to_buttons(target: Object, _name: String = name) -> void:
	var callable: Callable = Callable()
	callable = Callable(target, "_on_" + _name + "_focused")
	button_focused.connect(callable)
	callable = Callable(target, "_on_" + _name + "_pressed")
	button_pressed.connect(callable)


func button_focus(n: int = index) -> void:
	var button: BaseButton = get_buttons()[n]
	button.grab_focus()

func _on_Button_focus_exited(button: BaseButton) -> void:
	await get_tree().process_frame
	if not get_viewport().gui_get_focus_owner() in get_buttons():
		button.grab_focus()


func _on_Button_focused(button: BaseButton) -> void:
	emit_signal("button_focused", button)

func _on_Button_pressed(button: BaseButton) -> void:
	emit_signal("button_pressed", button)

the problem is on line 17

Seems like one of your children is not a Button, but in fact a Control node.

You are going through all children of this node here:

get_buttons is defined as get_children above; then connecting to property .pressed on each child.

1 Like