Godot Game Engine

Nodes and scenes

In Godot, we have several kind of structural element that will help organize the game. Nodes and Scenes are some of the most important, and a way to define how elements are mixed. They are available to user by GUI options which help any kind of contributor to work on its part without programming knowledge.


Nodes are really common in many software technologies. The best-known node-based system is likely the XML language, upon which the HTML language is based.

The principle of nodes is simple, just like a box in a box in a box...:

  • You have a first element often called root. This element can have properties, for example a position.
  • In this element you will add other ones. They will be considered as children of the first element, which becomes a parent. In most cases, children inherit their parent's properties but can also have their own. In our case, the default children position will be the same as the parent but could also be customized. Defining if a property can be changed is a question of design.
  • Moreover, those child nodes can have their own children and so on. At the end, this can result in a quite complex but well-structured organization.

In the editor, the Scene panel displays the node tree of the current scene. To help designers in the game production, the Godot developers have created many specialized node types that can have specific properties and methods. For example, you have the Sprite node to add a simple sprite, or the AnimatedSprite node to add several sprites meant to be used in an animation; you also have the SamplePlayer node to play samples (sound effects), and the SpatialSamplePlayer to do the same but taking into account the player/camera position in a 3D game.

Some nodes are specific to 2D games while others are meant for 3D games. An interesting point is that all those nodes come with properties that can be managed directly for the editor GUI, or at runtime using scripting, which really speeds up the production process. Godot's nodes can be viewed as predefined game objects that you use without having to program everything from scratch. Combining nodes is a way to create complex mechanics from simple base objects. At the end, Godot is coming with a quite huge quantity of node types; of course, it takes some time to get used to all of them and learn how to mix them, but most games can be made using only a small subset of the available nodes.

Nodes properties can be defined like this:

  • a node has editable properties related to its type,
  • a node has a name that can be used as an identifier,
  • a node is placed in the node tree and has one parent (apart from the root node) and any number of children,
  • a node is extendable (both via scripts or the node tree),
  • a node is scriptable and can receive callback functions.

An extract of available node base on «node» keyword only

For many of us, the most difficult part when learning how to use nodes will be to make decisions: how do I compose my node tree to get the result that I want? Those decisions should be first based on the game design and only then implemented in Godot. To do so, a good knowledge of Godot's architecture is definitely an asset. Some types will not work together because they are not designed to, and even for compatible nodes, the way the tree will be setup can affect the result (for example the drawing order of sprites depends on their position in the node tree). On the other hand Godot is very flexible, and there are many ways to achieve a given result; this can be daunting at first, but just get started with something that works for you, and refine it later if need be once you are more experienced. Learning by doing is by far the most efficient.

Scenes instances

As combining nodes is one the most important part of the game production process in Godot, why do we need scenes?

In fact, as powerful the node system is, you could make an indigestion. Puttings nodes in nodes in nodes in nodes can result in a really complex tree. The risk is to get lost in your own project because of the complexity of the tree. That is where scenes come up. 

Scenes instances will be our way to simplify our game tree. In Godot, a scene is not a place, or a stage where things happens. It is simply a combination of nodes that is saved on disk, and that we will reuse. In our design, we will use scenes to divide our game into more little part. In fact, as little as possible. The more little the scene content will be, the easier it will be to manage and reuse.

Scenes can be described like this:

  • a scene is a file with a .scn (binary), .xscn or .xml (XML) extension,
  • a scene can be instanced (reused) in other scenes,
  • a scene contains nodes that will be a part of the complete game.

In some ways, we have divided the node tree to a list of nodes and instanced scenes. This list will be much more easier to organize and, at the end, the game will result in a scene tree that will behave just like a simple node tree. And in fact, launching a game is just launching the main scene defined in the game settings.

An extra benefit of scene system is that it is a good base to work on to have better performance. As scenes can be reused, the runtime performance will be improved as there will be less memory usage. Of course, this is a basic optimization approach but if it is not done at this step, it will be hard to improve in other parts. In fact, scenes are the primary resource we will use to set up the game and they are worth the effort of learning how to use them.

Il y a une erreur de communication avec le serveur Booktype. Nous ne savons pas actuellement où est le problème.

Vous devriez rafraîchir la page.