Menu
CoddyTech

Connect a Signal

Part of the Signals and Collisions section of Coddy's Godot journey. Lesson 2 of 27.

A signal is a message a node sends when something happens. An Area2D sends body_entered when a body walks in. Nothing happens until some code listens.

To listen, you connect the signal to a function. Do it once, in _ready():

func _ready():
	body_entered.connect(_on_body_entered)

This reads: when body_entered happens, call _on_body_entered. Godot then calls it every time a body enters.

Write the function name with no brackets. _on_body_entered() would call the function right away.

challenge icon

Challenge

Easy

The zone's function prints Someone came in!, but nothing calls it. In _ready(), connect body_entered to _on_body_entered. Press Play and walk into the zone with the arrow keys.

Try it yourself

extends Area2D

func _ready():
	pass

func _on_body_entered(body):
	print("Someone came in!")
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Signals and Collisions

Practice on your own: Godot playground