What is a Signal?
- Game Development course
- Intermediate
- Lesson 67/83
- 4 min
Learn that Signals are used for event notifications in Godot.
What is a Signal?
In Godot, a Signal is a mechanism that notifies other objects when a specific event occurs. This architecture is known as the Observer pattern in software design and prevents tight coupling between objects.
# When an event happens, a signal is emitted
# Listening nodes are notified immediatelyFor example, a health bar doesn't need to know the player's internal script; it simply listens to a signal emitted by the player.
The Observer Pattern and Event Notification
In the signal mechanism there are two sides: the one triggering the event (publisher) and the one listening to it (observer). The publisher only announces that the event happened, without knowing who listens.
# Player dies -> 'died' signal is emitted
# UI, audio manager, and scoreboard can all listen to itThis keeps your game code modular, readable, and easy to maintain.
Practice Initialize the signal system
Define a _ready function. Inside, write a GDScript code that prints "Signal sistemi devrede" to the console.
Starter code
extends Node
# _ready fonksiyonunu tanimla ve konsola yazdirSample solution
extends Node
func _ready():
print("Signal sistemi devrede")Expected output
Signal sistemi devrede
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What is the most important advantage of using signals in Godot?
- Doubling the game's frame rate (FPS)
- Automatically saving all scenes to disk
- Locking the Transform component of nodes
- Reducing dependencies between nodes to provide loose coupling Correct answer
Explanation: Signals allow a node to communicate without needing direct knowledge of other nodes, providing loose coupling.
2 Understanding signal logic
# Godot olay yonetimi mekanizmasi
# ____ deseni gevsek baglilik saglar
# Godot olay yonetimi mekanizmasi
# Observer deseni gevsek baglilik saglar
Explanation: Godot signals are based on the Observer pattern for event-driven communication between objects.
3 Signal concepts
| Term | Meaning |
|---|---|
Signal |
Event notification mechanism |
Observer |
Observer side listening to the event |
Publisher |
Publisher side announcing the event |
Loose coupling |
Objects remaining independent |