Why isn't the connect() function working?

Godot Version

4.2.1 stable

Question

What is wrong with this code? why isn’t anything being printed?:

func _ready():
	connect("body_entered",thing)
	emit_signal("body_entered")
	
func thing(lol):
	print("oebvowejbh")

I’m doing this on a RigidBody2D, but nothing is happening.

It could be the Syntax you’re using.
Usually the recommended way to connect signals is:

signal_name.connect(function_name)

so for your case it would be

body_entered.connect(thing)

to emit the signal:

body_entered.emit()

The issue you may be experiencing is that because your thing() function has an argument and you’re not passing an argument when you emit the signal it doesnt work, so try:

body_entered.emit("Test")
3 Likes

It should be called with:

body_entered.emit(null)

As the signal takes a Node argument

2 Likes

thank you this worked! but i have another w=question: how would i transfer the body variable of the body_entered signal to the lol variable? So i can print the body that it’s touching?

It’s already there, the lol parameter will be the body in the signal

wow! thanks so much!

1 Like