These are the four fundamental concepts Godot games rely on: scenes, nodes, scripts, and signals.
We already saw them in action in our first project.
This guide will help you understand those concepts a bit more. You can come back to it anytime for a refresher.
A Godot game is composed of many scenes. A scene can be composed of smaller scenes and nodes.
Together, all your game’s scenes and nodes form the scene tree: your game will be organized in a tree of scenes. You’ll learn more about that when we work on bigger projects.
Now, scenes and nodes don’t do much without scripts. A script is a file containing code that you attach to nodes. The code executes on the nodes you link the script to.
Finally, you can make scripts react to events in the game world using signals. Signals are messages nodes emit when something specific happens to them, like a timer running out.
In Godot, you will break down your game into multiple scenes.
A scene will be anything meaningful in your game, like a character, a weapon, a door, a house, or an entire game level.
A scene can be of any size and complexity. When designing a scene, we focus on making a single thing for the game, like a character or a menu. If we need twenty nodes to do so, we use twenty nodes. If we need just three, we use three.
Imagine that you have several scenes: a room, a teleporter, and a chest. You could make a playable level scene by combining them into a new scene, as you did in the course introduction.
You can duplicate scenes as many times as you need. For example, your chest scene is a blueprint for making new chests.
We call each chest in your game an instance: a concrete reproduction of the scene. You’ll learn more about creating instances throughout the course.
To create scenes, you need small building blocks. In Godot, we call them nodes.
Nodes are like Lego blocks. They are the basic construction blocks of a game. Godot provides dozens of them. Here are four examples:
AudioStreamPlayer2D
can play a sound or music
soundtrack.Nodes provide you with all the essential features you need to make a game. For example, you can detect when the player is near a chest and tries to open it with an
. You can also use them to know when a character took a hit and should lose health.Notice how some nodes have the “2D” suffix. Godot supports 2D and 3D games, and many nodes have 2D and 3D versions. The suffix and icon’s color distinguish them.
By themselves, nodes often don’t do anything. They are part of the library of code Godot provides you. To bring nodes to life, you need to attach a script to them.
Scripts are files containing code that you attach to a node in Godot.
We use GDScript code exclusively in this course, but Godot supports multiple programming languages for experienced game developers who need that.
It’s best to think of scripts like parasites that attach to compatible hosts and take control of them.
Each node comes with a library of code that doesn’t do much by default. This code is waiting for you to use it. To do so, you write instructions in a script.
Your script will typically start with the extends
keyword followed by a node type.
What you write on this first line restricts compatible nodes. For example, a script starting with the following code is only compatible with sprites and nodes derived from sprites.
The extends
keyword means that “this script extends the
code of that node type,” giving your script access to all the functions
and variables the Godot developers coded for that node.
For example, every start()
function that
starts the timer. To use this function on the node, you have to:
extends Timer
.You can do a lot with just node and scripts, but you will quickly face a problem. Imagine a bullet that flies towards a monster. You want to know precisely when the bullet touches the monster and subtract health at that moment.
To solve this problem, Godot has a feature named signals. They are messages you can listen to, which tell you exactly when an event occurs.
For example, when boosting the ship, we start a
in our project. We want to know when the timer times out and lower the ship’s speed back.To do so, we connect to the timeout
signal. When the
ends, it emits the signal.
We connect signals to functions. When the timeout
signal
emits, Godot calls the connected function and runs its code, which is
how we react to the signal.
Signals, scripts, nodes, and scenes. They all work together to help you make games:
Note that these concepts are specific to Godot as every game engine works differently.
You will not find nodes themselves in other game engines. However, you will find sprites, sound players, areas, and so on. They’ll just work differently.