Getting Started With Godot's Scene Instances

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video you will learn about instancing something that happens all the time in games and saves us a lot of work instancing means reproducing a template you'll see how you can change a property in a scene and have it update instantly on all instances and more this video is part of our complete free calls to get you started with guido you will get to create two complete games from scratch in upcoming videos so if you don't want to miss out be sure to subscribe and turn on the bell okay back to scenes in godot scenes are templates from which you can create as many instances as you want here's an example with a ball which you will get to play with in a second the ball scene is composed of a rigid body node as its root named ball which allows the ball to fall and bounce on walls as a child we have a sprite note the balls picture and a collision shape 2d which gives the physics engine a geometric shape to detect when the ball touches something once you saved a scene it works as a blueprint we can reproduce the ball and other scenes as many times as we'd like here it's the main game level which has some walls on which the balls can bounce and roll now it's your turn to try it out you'll need to download a file we prepared for you you can find the link in the description below and it will download the project as soon as you click it you want to head to where you saved the zip file and right click extract it normally in most operating systems you can do that and then i'll import it in godot so to do so i'll copy the folders path and we're going to open goto in a new workspace on my desktop so i'll click import and paste the project's path then click import and edit to open the gudu project here we land on the main scene it contains some walls that we'll use to make balls bounce if you go to the bottom left to the file system dock you have a ball.tscn file you can double click to open it and see our little ball here let's head back to the main scene where we'll create an instance of our ball to do that you can use the icon in the scene dock in the top left note that to create an instance it's like when creating a node you need to select a parent in that case we'll click on the main node if you don't and you try to add a scene you will get an alert like that so click on the main node and click the scene instance button to get a list of all the scenes you can instantiate in your project here we want to instantiate the ball will get added to the origin of the world exactly it will get added at the position of the parent but the nodes like main and wall container don't have a position in that case it gets placed at the origin so you can select the ball by clicking on it in the scene and make sure you have the select mode selected and click and drag to move it closer to a wall you can then press f5 to play the main scene enter your ball fall and bounce alright well now going to create a second instance of the scene with a different method so there are two more you can click and drag the ball scene in the view or you can click and drag it in the scene dock note that you don't want to insert it as a child of the other ball i'm going to offset it just so you can see that when you have a ball as a child of another they move relative to one another so you don't want that so if that happens you want to click and drag to move the ball as a sibling of the first one and you'll see its name changes so they don't have the same name and now if i move one it moves independently from the other so i'm going to move them on either side of the bold and press f5 so you can see that they now fall and exist independently so this is what instances do for you you create reproductions of a scene and every reproduction is independent from the others mostly as you will see note that in this project at runtime you can click to create new balls okay so that's a start but we can do much more with scenes and instances we can change the default property of the ball scene to modify all the balls in there we can also modify an individual instance to make it different from all the others so we'll do this now open the ball scene by double clicking on while the tsen or clicking the tab select the ball node and in the inspector we're going to click on the physics material and we're going to modify the bounce property we're going to crank it up to 1. now if you press f5 you're going to see that the balls are much bouncier so we modify the property in the source scenes and all the instances got updated accordingly note that when you press f5 or f6 godot is automatically saving everything in your project for you we can not only do that but head back to the main scene by clicking the main tab and we're going to create a new ball that will be different from the others to do that a third method is to press ctrl d and then click and drag to duplicate the selected node you can also right click in the inspector click duplicate you will see the new ball appear there and then you need to move it by clicking and dragging so i'll select my ball for and i want to change the gravity scale so i'm going to lower it down to one now if we play the game you will see that three balls are bouncy and falling fast and one is going super slowly what we did here is you can see that little cancel or undo arrow which you can click to revert the value to four we modified a default property on one instance and one instance only we can modify any other property in the ball scene and all the balls including this one will get modified except for the gravity scale property and you can do that with all the other properties you can see in the inspector i have one little disclaimer when it comes to that it's that physics material here when we click it you can see that the color of the outline changes and it's kind of a sub component of our object to be precise as we can see in the tab here it is a resource goto uses lots of these objects that are fundamental and go to projects called resources which you can attach to nodes these resources are by default shared by all the instances of the scene godot stores one resource in memory and every instance is going to point to that resource so even if i'm in the main scene if i change the bounce back to zero and play the game you will now see that the balls don't bounce anymore even if this one is falling slower than the others i modified the resource which is shared by all the balls you can make the results unique on one element to do that you right click on the resources name so the physics material and click make unique you will see now if i expand the resource category the path disappeared if i select another ball and go there you will see that the path is different okay so i'm going to set the bounce up on this ball the one where i made the physics material unique and press f5 to play the game and now you will see that well it's really slow but it's bouncing unlike the others so you just want to be wary of that with resources the important part is that resources are shared in memory that are shared by all instances in the next video we'll talk about the five programming languages you can use to script your games in godot we'll talk about the pros and cons of each but more importantly you will learn what are your options if you'd like to get more content on our website you can find a series to get started with godot it's different from this one as it really focuses on how to get started as a programmer and shares insights that are really useful but that are beyond the scope of this video series it's completely free and you can find a link to it on the screen in the description below don't forget to subscribe and i'll see you in the next one bye
Info
Channel: GDQuest
Views: 21,002
Rating: undefined out of 5
Keywords: godot scenes, godot tutorial for beginners, godot getting started, godot instancing, godot instances
Id: _ImAgihyy3A
Channel Id: undefined
Length: 8min 35sec (515 seconds)
Published: Thu Mar 18 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.