Scenes and Scripts
Scenes in Godot are typically used to create and organize the various game objects in your project.
For example, you might have a player scene that contains all the nodes and scripts that make the player’s character work. Then, you might create another scene that defines the game’s map: the obstacles and items that the player must navigate through. A third scene might represent an enemy, of which you probably want to have many throughout the game.
Organizing your game objects in this way brings multiple benefits:
- It’s a great way to manage complexity. When you’re working on one scene, you don’t need to worry about the others. You can focus on all the functionality of your player character without getting distracted by other parts of the game.
- Since scenes are self-contained objects, you can use them as if they were nodes. Adding the player to the level is as easy as adding any of Godot’s built-in nodes.
- Many game objects are not unique - you’ll want to have lots of them in the game. Whether you are doing it in the Godot editor or via code, adding copies of the scene object is easy to do.
Creating Scenes
Notice that the tab where you added the Sprite2D
in the previous section is called Scene. In this tab is where you add the nodes that you wish to use to build your scene.
Nodes in scenes are organized in a tree-like structure. Each node may have any number of child nodes, while each node only has one parent node.
For example, a scene representing the player in your game might contain these nodes:
Don’t worry if you don’t know what all those nodes are for just yet. The point here is that each one brings some type of functionality that you might want your player object to have.
The Scene Tree
All of your game’s scenes and nodes exist together in the scene tree. You can think of the scene tree as representing your entire game - everything that’s currently running and active.
As you create new objects during gameplay, you’ll add them to the scene tree. As things are destroyed, you’ll likewise remove them from the tree.
Scripting in Godot
Godot supports two official programming languages that you can use for scripting nodes: GDScript and C#.
- GDScript is the dedicated built-in language, providing the tightest integration with the engine, and is the most straightforward to use. All of the examples on this site use GDScript. For the majority of projects, GDScript is the best choice of language. It is very tightly integrated with Godot’s Application Programming Interface (API), and is designed for rapid development.
- C# is best reserved for those users who already have a good understanding of Godot, and have a specific need. For those that do, Godot gives the flexibility to use a combination of GDScript and C# where you need them.
If you are already familiar with one or more other programming languages, you should find GDScript very straightforward and easy to pick up. Godot is an object-oriented programming environment, so you should be comfortable with the concepts of classes and objects. The Godot documentation has an overview page that summarizes the syntax here: GDScript Reference
For a more detailed introduction to GDScript, see the Introduction to GDScript on this site.
If you’re new to coding entirely, then you may find that you need a bit more support. We recommend the Harvard CS50 open courseware. It’s a free course that will give you a great foundation for programming in general. Don’t be intimidated by the time commitment - the effort you put in up front will save you countless hours of frustration later on.