Help with signals

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

So, I want an action to be performed when a kinematicBody2d enters an Area2d(the action is printing something), so I put a connection between these two bodies using the command “_on_Area2D_body_entered” that can be found on the “Node” tab in area2d.

This is the code inside kinematicBody2d:

  func _on_Area2D_body_entered(body):
    print("Hello World")

In this case, “Hello World” is printed, but the problem is that it is printed without the kinematicBody2d and area2d having to contact each other… it just prints automatically when the game starts. How can I fix this and make it so that the output is only printed when the two bodies actually contact each other? Thanks in advance.

:bust_in_silhouette: Reply From: Eric Ellingson

Are you manually calling this method from somewhere? What you want to do is select your Area2D node, then in the inspector on the right, select the Node tab, then select the event/signal you want (in this case probably body_entered), then click the Connect button at the bottom, and select the node you want to listen for that event, in this case it is the KinematicBody2D.

So I think the issue here is that you created the function for handling the signal/event, but you did not make the actual connection.