Menu
CoddyTech

Another Node's Signal

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

A script can also listen to another node's signal. Get the node with $, then connect its signal:

$Switch.body_entered.connect(_on_switch_body_entered)

This reads: when Switch sends body_entered, call _on_switch_body_entered. The function is in this script, so it can use this script's nodes, like $Light.

Games are often wired this way. One main script connects the switch, the light and the door, and each of those stays simple. Godot names such functions _on_, then the node, then the signal.

challenge icon

Challenge

Easy

Main has a function that turns the light on, but nothing calls it. In Main's _ready(), connect the Switch's body_entered to _on_switch_body_entered. Then step on the green switch.

Try it yourself

extends Node2D

func _ready():
	pass

func _on_switch_body_entered(body):
	$Light.visible = true
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