 I've got a little Godot project from a past screencast episode where there's a player and they have a health bar Press the space bar and their health decreases In the scene tree, you'll see I've got a main node, which is a node 2d I've got a color rect which is a background color. I've got an Icon the health label and the health bar what I want to do is take the icon health label and health bar and make them into their own scene because you can compose your Godot scenes with instances of other scenes and that's how objects if you're familiar with object oriented programming are sort of created and used and managed in Godot so you'll create a scene and they go instantiate them and then you can actually go into your scene of your Object and change it and edit it accordingly. It's a little different at first But you get used to it and it feels pretty intuitive. So we're gonna start by we'll add a node 2d To wrap our player in so now we have this new empty node We're gonna go ahead and select these three with shift and I'm just clicking them And you drag them into their nude parent node. We'll call this player and then We have a script here that handles all of the functionality for the player I'm gonna go ahead and we're gonna Detach it from the main node of our game and instead we're going to attach it from Here so and I want to rename this actually so what we'll do is we'll Down here. We'll rename the script to be player dot GD and we'll just Since our player Wrapping node as a node 2d that can say the same and then we'll associate Our script existing script here by clicking and selecting open in the mode So let's quick run our game. Make sure we didn't break anything Everything is still functioning Now what we'll do is you can right-click on any node and you can say save branch as seen And we'll call it player and we'll save it and then you see how that you I changed now We have an incident. We see it's an instance of player of type node 2d there's a Little movie clapper so you can open in the editor and you can open the script right from here too now if we save Let us and look at the 2d scene. Nothing's changed. We rerun it Everything works just as it did but you'll see down here or a player scene We can actually open it in its own tab up here You can also click by clicking the movie clicker clapper And now we have our own scene with the player and there's a little oddities that we want to change before we were dragging around Our player in the space of the screen When they were just their own nodes, but what we want to do actually is make player Center in its own scene and this helps because When we instantiate instances of it we can then move It around accordingly while still having its origin centered That's like the one little weird gotcha. It's like When you save a branch as its own scene you want to re-center it so that see this little plus icon That represents the origin of the sprite and that helps determine its global position And we want to be able to change the player's position which we'll do very shortly But now that we've centered player here and you can even run this scene on its own It's not super useful because it's over here way off the camera view So you could grab all this grab the origin and I don't know if this will work So that just ran the whole game Now we run that scene now we can see it. Let's move player I'm just curious if we Put the player here run the whole game Yep that That works so you can When you're like editing the scene for the player as long as you move everything including this centerpiece To It's new location. It shouldn't affect it in The scenes that instantiate the scene so that can help you with play testing and stuff, but you got to make sure that you Move everything Including the center here. Otherwise the positioning will be kind of messed up But as long as it doesn't move it here, that's important See if we selected this and moved it shifted it, right? You see it shifts it Within the instance of the player scene, which we don't want we want it to all be together and now we can preview it on Our own outside of the context of our game and we can preview it in our game So you can compose a bunch of them now We can even delete this node and Instantiate a new instance of player you can come down here to player TSC and And you can drag it in and Change it accordingly. So that's an option. You can drag it in We'll delete it. There's another way to do it. Let's see if it comes up here. I think it's maybe Instantiate child scene. So yeah, if you click the gear the link icon there You can select a scene and instantiate it. So now we've got our player and it's centered and Everything's good there now we can edit our player and we can say something like You know in funk process If Input action is action pressed We'll just do UI left for the left arrow key then we'll say position dot x minus equals one Run our whole game if I press the left arrow key See our whole player now moves left And we can even we'll just make it move left and right really quick We'll add that there. We'll make it just ever so faster That should be a variable, but For this demo, it's okay. So now we can move left and right Accordingly in our game scene here in player if we go and just run our player scene Imagining at a game where there's a whole bunch of things going on But you just wanted to test and get your player movement working. Well, that's when you would run just the scene of your player Then you could go back in and test it in the game and see how it feels So by breaking your game up Into a bunch of scenes that you instantiate instances of and Composed together you're able to test your scenes that you've created in isolation And then see how they function within the game this becomes really powerful as you're building and refining your game and Working pretty quickly So just to recap you can right click on any node in the scene and save branches scene You can drag the scene in like we could have two players and run it and Now if we press left and right Both scripts are executing on the player. So maybe you'd want to assign settings and That sort of thing. I guess while we're in here. We might as well talk about a Couple things to to help surface some interesting parts. So Before we wrap up remember, I said this should be a variable. Well, let's make it a variable Let's have it be speed and we'll say Bar speed is equal to two like we had it and that feels It's not working. So let's see what's wrong. Okay, we have an issue there. I didn't type it in Okay, now we've got a moving and two is there we can actually do export bar Speed to and then while the game is running in the inspector if you click a player You can change that instances speed So instead will make the first player move at five and the other move at two and you see they move at different rates Because each instance has their variable value for speed set to a different one. We make this one one. It'll move even slower if we make it 20 It moves way faster So that's a quick like Additional tip is that if you have a variable a value that varies you can do export bar and change it accordingly and You can also then in the code like if we have main gd Here and we have ready you can set those values in your code, too You don't just have to do it in the inspector and so like let's set player to speed to two there But here on ready. We'll just say player two dot speed is equal to five run our game and now you can see it matches the five that we set for player One in the inspector now I changed now player one on the left is moving faster. So you can Change these variables that you create in your instances with code elsewhere just becomes really really useful and Yeah, so that's the basics in an isolated example of how to compose your game of scenes and I think you'll see in Examples where you're building a full game and tutorials is that this pattern juice a lot But it can be helpful to just see it in isolation and explain further Hope that's helpful. Thanks for watching