Welcome to the second lesson in the “Make a Simple Game in Godot” series, my name is Chadot and today I will teach you what SCENES are and how to create one.
What is a scene?
Godot is NODE based. This means everything you make will be made out of nodes!
Let’s say we want a weapon in our game. We build this weapon using different nodes. These nodes could be different parts that makes the weapon look and work as intended.
We could have a node for the graphics of the weapon and this graphics–node itself could be made up from even more nodes.
For example if our weapon is an axe, then we could have a node for the head of the axe and another node for the handle of the axe.
We can also add collision nodes, particle effect nodes and animation nodes to create a more complex weapon.
Now, all of these different parts of the axe will all be under one common node, and it is this root/parent node that is called a SCENE.
So even scenes are nodes!
This also means we can import multiple independent scenes into a one single scene to build an even more complex scene.
If this sound complicated, don’t worry, it will all make sense to you with each lesson.
Here is an example of how the Axe scene would look like if we made it:
Making our first scene
After creating our project from the last lesson the very next thing we are prompted to do is to create a root node by selecting one of four types: a 2D Scene, a 3D Scene, a User Interface Scene or a “Other Node” scene.
This might seem like a “permanent” choice that you are forced to make, BUT this is not true at all. And you might also think these nodes that we are first presented with are very important and we must pick one of them. The answer is NOT SO AT ALL!
These choices are just an example of the most commonly used node types, and that’s it. At the end of the day, they are just nodes and it doesn’t matter which one you pick.
If you select the Other Node option you will see what I mean! There is an ocean of nodes to choose from and we can even create our own types, but that’s for a more advanced course! The existing nodes are more than enough for what we need.
Selecting our first node
Now go ahead and select “Other Node” and look for a node called HingeJoint under the Spatial node.
After pushing create or double clicking on the HingeJoint we are taken back to our previous view but this time we see a couple of differences.
A new scene was created for us, currently named [unsaved](*) and the HingeJoint we chose is now the root node of this scene.
And we have also received our first “error”, if you hover over the yellow triangle next to the HingeJoin it will read “Node configuration warning: Joint is not connected to any PhysicsBodies”.
Saving our scene
Perhaps the error will go away if we save our scene! Saving is very important and we can do so by using a keyboard shortcut (Ctrl + S) or going into the Menu > Scene > Save Scene, it is crucial to find what is most comfortable for you and turn it into a habit.
Now go ahead and save the scene.
Because this scene is being saved for the very first time, a pop-up will pop out and prompt us to give the scene a filename and a location for where to store the scenefile.
The save location is limited to our project folder, the “res://” path is an indication that we are in the root folder of our project.
Now before you save, let’s first create a folder that will hold our scene and its contents. The reason is because we want a modular approach when building our game, even if it is a tiny game.
Modular simply means creating something that isn’t limited to one project, in other words, we should be able to take whatever we create and re-use it in our future projects without much hassle or wasting time re-creating the same thing from scratch.
Create a folder called “MainMenu”.
It is important that you pay attention to whether something is lowercase, uppercase, connected, or separated. In this case, the name of the folder is connected and is using something called PascalCase.
Now that we have our folder we can go ahead and save our scene by clicking the save button.
Everything can be changed without much trouble
Now, you might be asking yourself, WHY THE HECK did we create a HingeJoint node as the root node for our menu scene! It doesn’t make any sense!
Well, it does make sense if we were going to create a complex 3D menu system, but even then you would not begin with a HingeJoint… doing so would make you kind of UN-HINGED, ha ha ha (laugh or I will give you an F).
Anyways, in our case we are not making a complex 3D menu system, so you are right. The HingeJoint node is wrong for us right now. And on top of that, the filename of our scene is also wrong. This is all intentional because I want to teach you something very important!
You can’t do anything wrong in Godot, everything can be fixed without breaking the entire project!
So don’t be scared, don’t be too careful, don’t let fear hold you back. Use whatever works, throw things around until it works, you can always fix it later!
Changing node names and types
So, let’s now fix these mistakes!
Double–click on the HingeJoint node in the scene tree.
This allows us to change the name of the root node for our scene.
Let’s name it “MainMenu”.
Now select the same node and, using our mouse—click the right mouse button while the mouse cursor is still on top of the node.
This brings out a special menu for nodes.
We are going to change our HingeJoint node to a completely different node type. So go right ahead and click on the Change Type in this special menu.
This brings us back to the node selection window that we saw earlier.
Now we will pick the correct node type as the root node for our scene. Browse through all the node types until you find a node called Control. If you can’t find it then you can also use the search bar.
Push the Change button to apply the changes and now we should have a Control node named MainMenu as our root node for our scene.
Now save the scene again, this time our changes will be saved immediately without a pop up telling us to write a name and whatnot. The pop up only happens when we save a scene for the first time. Or if we select “Save As” instead of “Save”.
We are getting there!
Pay attention to the icon in front of the node name. It has changed!
All nodes have a special icon that distinguish them from each other. I highly urge you to pay attention to these and try to memorize them as you continue to use the Godot Game Engine.
Memorizing these icons over time will aid you a lot when it comes to working faster and recognizing the purpose of each node. This is especially true when we start changing the name of the nodes, which makes it impossible to know what type of node it is unless we hover the mouse over to verify it.
By memorizing we can skip this whole process and save a lot of time!
Now, I’m not saying you should sit down and memorize all of them in one sitting. Instead, just be aware of their importance and purpose.
There is one last thing we need to correct before we are done here, we need to change the name of the scenefile that we created previously. It is currently named HingeJoint.tscn, which is wrong for two reasons:
- Filenames should never be in PascalCase
- HingeJoint is the wrong name
All files must be lowercase and use snake_case. This is of course not a rule, but it does create a unified style and if everybody in the industry uses the same styling then it becomes easier for everybody to navigate and understand a project.
Anyhow, let’s change the filename of our scene!
Head over to the bottom–left of the screen to a viewer called FileSystem. This little window allows us to view all the files in our project.
Here we can also see the new folder that we created and named as MainMenu. And inside it we can see our scene’s savefile which is named HingedJoint.tscn, let’s correct the name.
Select the HingedJoint.tscn file and right–click the mouse button to bring out a special menu for file items.
Click on the Rename option.
This will allow us to rename the file for our scene.
Go ahead and type in the correct filename for our scene, remember to use snake_case for filenames.
Since this will be our menu scene, and the scene is called MainMenu in our node viewer, we will go ahead and rename the filename to main_menu.tscn
This keeps thing organized, the filename is the same name as the node name, this will help us avoid any confusion and avoid the risk of losing track of where our content is and what our content does.
Hit the Rename button once you’re done writing the correct name.
Now we have our scene using the correct node type and we have also named our node and filenames correctly. And to top it off, we even created a folder to keep things organized as we introduce more nodes and files as we continue constructing our main menu!
You have learned the process for creating scenes using the correct node type. And how to apply some basic styling standards for naming scenes, nodes, folders and files.
You have also learned how forgiving the Godot Game Engine is if you make mistakes and how easy it is to correct mistakes without any problems.
Can you also guess what we will be making?