Hello and welcome to another episode in that Godot basics tutorial series.
In this episode we will be taking a look at nodes and resources and towards the end, I'm going to show you through Godot how we can not only create nodes and resources but also some cool tips if you are in fact a beginner. Now if you do know how to use Godot this episode will most likely be redundant. However if you are new to programming and definitely new to Godot this episode may in fact provide you with some tips.
Now let's start with nodes. Nodes represent behavior as a matter of fact.
Nodes give us functionality such as drawing a sprite simulating physics managing player speed and so on. One thing to note because nodes have functionality. The Godot game engine relies on nodes basically are nodes. Determine what features and functionalities are provided to us. Next thing we need to take a look at is resources. Resources are data containers all resources do is hold data. Now as a matter of fact nodes rely on the data contained in resources and resources are quite easy to understand as long as as long as the item needs to be saved on to disk then that is in fact a resource.
Some examples would be GDScript files. GDScript files are in fact resources on top of that scenes scenes are in fact resources now.
Now let's go ahead and take a look inside
Godot. Now I went ahead and created a new project. As you can see here when you've created a new project you're taking to this screen. First let's go ahead and take a look at nodes. So to our left because we've just created a new project file we are required to create a root node for our scene our non-existent scene. Now you do have the option of picking 2D, 3D user interface over let's go ahead and look at the fourth option called other node as you can see here when we created the other node we were able to open up this create new node window. And
And so that's in fact what we're doing we are in fact picking or rather creating a new node.
Now I want to show you this.
I'm gonna go ahead and minimize node and you'll notice that this is the only node available to us. And this Node in fact inherits from the node class. And so at minimum our Godot project requires our root node to at least inherit from the node class.
So a node that inherits from node class.
Now if we expand it we're gonna see all of our nodes children or rather subclasses and you can see everything here. And these are all subclasses of the node class. And so not only do these subclasses have their own properties and methods but they also inherit the node classes properties and methods. The two most important nodes I want you to pay attention to is one the spatial node which we use when we want to create 3D game objects or work in the 3D scenes. The second item I want you to look at is the canvas item. Now
Now notice how it's great out our canvas item our canvas item is in fact a class. However if we were to expand the canvas item you'll see that no 2D inherits from canvas item or rather no 2D a subclass of canvas item and canvas item is a subclass of node. So if we were to pick our Node 2 D class not only do we have properties and methods of the no 2D class we also have the properties and methods of canvas item and we have the properties and methods of node. So I'm going to go ahead and pick no 2D.
We're gonna go ahead and create that and as you can see in the inspector we do in fact have some things. First we have transform in z index from no 2D.
We do in fact have canvas item visibility and material. Notice that these are two choices we have to manipulate properties among canvas item class. And last but not least we have our node section where we can manipulate things that belong to the node class along with pause and script. Now that's what I wanted to show you is that our nodes do in fact handle behavior in this case are no 2D handles the behavior of our position rotation degree and then inherit behaviors from canvas item and node and this will be more in parent.
If we were to for example use the sprite node so notice how when I clicked in drag the icon P you file onto our scene we did in fact create a sprite node unto our scene tree. Now if I went ahead and I clicked our sprite notice or sprite has behaviors and functionalities we can manipulate under these bright section and then on top of that we have behaviors and functionality given to us by the no two D class and everything in the inheritance chain that includes canvas item and node.
One thing I want to point out is that when we created our node we don't have a script attached to it.
So notice that you notice how we can move things around and manipulate our sprite node. Now I'm gonna go ahead and press play it's gonna give us an error. We're gonna go ahead and create a default scene file so we can run our game. Notice how are images showing yet. If I were to for example move this to the right or sorry to the left and we'd go ahead and press play I'm gonna have to go ahead and pick a main scene. However when I do you'll notice that it moves. That means our sprite class or sorry or sprite node actually has the ability to retain information when we edit from the inspector.
So you may hear a lot.
A node happens to also be a script and that's in fact true because even though we don't have a script attached to it our node is able to retain information and it can use that information to go ahead and act upon it. In this case.
Notice her position is saved when we move around in our scene.
On top of that we also have rotation degrees. It will retain that information. You can see that it's edited here and when we go ahead and press play again you're gonna notice that it retains that information. So that's what I wanted to show you. Nodes do in fact contain functionality and behavior that the Godot app needs in order to well show you something. Now you can have even more fine tune control when you attach a script onto our nodes. In this case the sprite node and they know 2D node and as a matter of fact G.D.
files are resources. I'm going to show you that right now. So go ahead and right click and come down to New resources. Now. What I'm going to show you is the exact same thing as new script and later New scene however because our GD files are in fact resources we can go ahead and click the new resource option when we write click in our file manager and if we scroll down there's gonna be a section called script and it's right here.
Now one thing you need to know about resources is that resources just like node is in fact a class. So at the very top our resource at minimum needs to inherit from the resource class and all of these classes inherit from the resource class. So the resource class has children and everything listed here are children.
And so when we go down to script apologies.
So when we go to script you'll notice that it's great out. But as a matter of fact script is a class it's a class we can't pick but it is in fact a class.
And these script class inherits from the resource class. And so when we drop down you'll notice three options because I'm not using the Godot model version.
You'll notice we have G.D. Script, native script, and visual script.
However if you do have the model Godot application you will see C# and G.D. script actually inherits from script or resource G.D. script inherits from script and script inherits from resource it.
So that's another thing. And that is when we're creating a new resource or creating a new node. It's shown to us in order of at the top the parent and towards the bottom the child or children. And so just like the node example of the resource X and behaves the same way when you go ahead and create a new resource. Now I'm gonna go ahead and try to find script again.
It's really hard to find but when I do I'm gonna go ahead and create the cheesy script file and so when we go ahead and create it. Notice how it's telling us to name our GDP script file. We're just gonna go ahead and leave it at the default because the whole point of this was to show you that GD script files are in fact resources.
Now I'm gonna show you one more thing we're gonna go ahead and create a new resource except I'm gonna show you that scenes are in fact a resource. So I went ahead and I just typed here PAC.
But what we're trying to search is packed scene now a scene file is in fact a packed scene class. So what that means is we have our resource class at the top and everything beneath it our children and the path scene class inherits from the resource class
so if we double click it you'll notice that we've been given the option to go ahead and create a new scene file. I'm gonna go ahead and click save. So you'll notice that down here we have the new packed scene file and it happens to be a scene file. Now if you were to click this you'll notice how we're taken to a tab and this tab in fact happens to be our scene. We click here we're taking tour no 2D scene. We click here we're taking a tour and noticing now this is what's given to us by default. However we can in fact change our route.
Node and there we go. And now our new packed scene, scene file now has the node to the is the route known telling Godot that this scene in fact is a 2D scene. And so that's what I wanted to show you in this episode that nodes do in fact have behaviors and we can go through the inspector tab to see those behaviors and that scenes and G.D. files are in fact resources.
Now there are a lot of resources and there are a lot of nodes you can choose and pick from.
So that's all I have for you in this episode I hope you learned a lot. If you have to take one thing away from this as a beginner since you knew the most important thing is that I hope you took away that when you create a new node or a new resource that it is listed to you in a tree format.
And at the top the parent class and everything underneath it happens to be subclasses brought out just means you can't pick it but it is in fact the class. And in this case even though these are all classes they in fact create us a node that gets attached to the scene. And when you create a resource, keep in mind that it creates a file that adds itself into the file system. And so that's what it means to be a resource that it's saved onto the disk. So that's one thing I want you to or rather that's another thing I want you to get from this episode is that resources are saved to disk in this case saved into our file system and nodes are just functionality and behaviors Godot needs to do certain things and those are added on to the scene.
Well that's all I have for you in this episode I hope you learned a lot. If you have any questions or comments please feel free to leave them in the comments section down below.
I look forward to seeing you in the next episode. Have an amazing day.