Nodes & Resources| Godot Basics Tutorial | Ep 11

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to another episode in the 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 our 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 onto disk then that is in fact a resource some examples would be Gd script files Gd script 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 taken to this screen first let's go ahead and take a look at nodes so it's we're left because we've just created a new project file we are required to create a root node for our scene are 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 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 notice that this is the only node available to us and this note in fact inherits from the node class and so at minimum our Godot project requires our root note 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 notice how it's grayed out our can decide on 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 is a subclass of canvas item and canvas item is a subclass of note so if we were to pick our no 2d 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 note 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 less 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 or no 2d handles the behavior of our position rotation degree and inherit behaviors from canvas item and note and this will be more impaired --nt if we were to for example use the sprite note so notice how when I clicked and drag the icon PNG file onto our scene we did in fact create a sprite note onto our scene tree now if I went ahead and I clicked our spray notice our sprite has behaviors and functionalities we can manipulate under the sprite section and then on top of that we have behaviors and functionality given to us by the no 2d class and everything in the inheritance chain that includes canvas item in note 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 yet 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 our image is showing yet if I were to for example move this to the right or we're sorry to the left and we 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 spray class or sorry our 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 how our 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 notes 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-tuned control when you attach a script on to our notes in this case the sprite node and the node 2 D node and as a matter of fact GD files our resources and 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 right-click in our file manager and if we scroll down there's going to 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 apology's so when we go to script you'll notice that it's grayed 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 the 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 mono version you'll notice we have GD script native script and visual script however if you do have the Monell goodell application you will see c-sharp and GD script actually inherits from script R resource Gd script inherits from script and script inherits from resources 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 acts 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 GD script file and so when we go ahead and create it notice how it's telling us to name our GD 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 PA scene 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 our 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 tap on this tab in fact happens to be our scene we click here we're taken to our no 2d scene we click here we're taken to our note scene now this is what's given to us by default however we can in fact change our route note there we go now our new pact scene scene file now has the no 2d as the root node 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 GD files are in fact resources now there are a lot of resources and there are a lot of notes 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're new 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 braid 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 on to 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 safe 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 comment section down below I look forward to seeing you in the next episode have an amazing day
Info
Channel: Godot Tutorials
Views: 6,304
Rating: undefined out of 5
Keywords: Godot, GDScript, Tutorial, Series, Beginner, Learn, Code, Practice, Coding, Learning, Help, c++, c plus plus, programming, program, game, loop, main, Soft, Intro, Introduction, Nodes, Resources
Id: wyP_2nlV3no
Channel Id: undefined
Length: 11min 32sec (692 seconds)
Published: Sun Jun 14 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.