Godot makes extensive use of object-oriented design concepts at its core. This Godot tutorial will help you understand how it works, examining its fundamental elements: Nodes and Scenes.

Don’t worry if some concepts will not be clear to you when reading this post: in the next tutorials I will try to explain everything with simple, practical examples.

Nodes

Nodes are the fundamental building blocks for creating a game. Godot offers many different types of nodes, each with a specific purpose. However, any given node always has the following characteristics:

  • It has a name.
  • It has editable properties.
  • It can receive a callback to process every frame.
  • It can be added to another node as a child.

The last point is fundamental and tells us that a node can have other nodes as children. When arranged in this way, the node become a tree.

nodes organized in a tree

The ability to combine different types of nodes in a tree creates a powerful tool for organizing projects and allows the creation of nodes with complex behaviours.

Nodes follow an object-oriented design: they always inherit from their parents up to the Node class and can be extended to add new functionality. For example, Sprite is a Node2D, a CanvasItem and a Node. It inherits all the properties and features of its three parent classes, like transforms or the ability to draw custom shapes and render with a custom shader.

Scenes

A Godot Scene could be a Level, a Character, a Weapon, an Item or any other thing you can imagine. In Godot, running a game means running a Scene.

A Scene is composed of a group of nodes organized hierarchically as a tree. Essentially, the Godot editor is a scene editor. It has many tools to work on 2D and 3D scenes as well as on user interfaces, but all these tools ultimately edit scenes and nodes that make up them.

Also, a scene:

  • Always has only one root node.
  • Can be saved to disk and loaded back. Scenes saved to disk are called “Packed Scenes” and have a .tscn filename extension.
  • Can be instanced.

What does instanced mean? Creating a single scene and adding every nodes to it might work for small projects, but for complex ones, the number of nodes can easily become huge. To address this, Godot allows a project to be divided into any number of scenes. Those scenes can be added (instanced) into another scenes as if they were any other nodes, even at run-time by scripts.

Scene B was instantiated into Scene A

For example, you can create a House scene and a Church scene, than instance them multiple times inside a City scene. Change House properties, save, and all the House in the City will update instantly.

Furthermore, you can inherit and extend any scenes. You may create Fighter and Wizard scenes that extends your Character. Modify Character in the editor and both Fighter and Wizard will update as well.

With Godot, you have all the freedom to build the structure of your projects to reflect your game design.

Conclusions

We learned that nodes and scenes are the building blocks of Godot. Now that we have a basic understanding of how projects are organized in Godot, we can make our first test project!




0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

By continuing to browse this Website, you consent to the use of cookies. More information

This Website uses:

By continuing to browse this Website without changing the cookies settings of your browser or by clicking "Accept" below, you consent to the use of cookies.

Close