Error connecting to nodes

*Godot Version 4

When I run my game, I get an error connecting to nodes related to buttons on a Main Menu interface. Attached Capture.

By chance are you Autoloading the script as well?

Hi,
you could try this:

var new_game_button

# Called when the node enters the scene tree for the first time.
func _ready():
	new_game_button = find_child("NewGameButton")
	new_game_button.connect("pressed", Callable(self, "_on_new_game_button_pressed"))

Then if you move the buttons about under different controls, you don’t have to worry about updating the variables.

new_game_button.pressed.connect(_on_new_game_button_pressed)

Is the preferred and better syntax btw, cleaner and safer

1 Like

Why not connect the signals through the editor in the Node tab?

1 Like