Guide to the Godot game engine/What is a node

Nodes are the building blocks of Godot. They can be combined into trillions of different combinations. There are many different types of nodes, like and.

Every node goes under this one. It is the basic node that defines all others. See it as the parent and the grandparent of Godot and its nodes, and all the games that Godot has been used in. It stores common things like name and script. It can be used instead of or  when making objects that store data, and are not needed to be shown on the screen or have a position.

CanvasItem
Unlike Node, Canvas Items are positional, and implement draw code. They are used for all 2D objects, and have two main node types that inherit it:

Used for the GUI. It contains options like whether to ignore mouse input, receive it and let it pass to other UI, or receive it and stop it reaching other UI. They also allow margins and anchors, allowing a Control node to stay in a certain part of the screen or stretch when the window expands or shrinks.

These are used for 2D game elements, like and. They are drawn on the canvas, which is drawn on top of the 3D view. Well, its actually the other way around. 3D is actually drawn in the background of the canvas, if there is an active Camera3D in the scene.

Used for 3D game elements. They store positional data, rotation, and scale. They do not draw onto the screen. For this, you need to use the node that inherits Spatial. You need an enabled Camera3D in the scene to actually see the 3D world.

Making custom nodes
Firstly, you need to decide what it'll do. Is it some variant of ? Or is it a custom ?

After you decided what it does, you must decide what Node it inherits. This is important. You don't want to use Control if you want a 3D button, or Spatial for a timer.

In my opinion, this is the recommended node for each type of object you want to make:

Node: Use for objects that won't be part of the GUI, 2D or 3D worlds. Existing examples are Timers, and.

Node2D: Objects for games that are not used in the GUI. There are exceptions, but in general, don't mix up Node2D and Control too much.

Control: For GUI, like menus, HUDs and certain game elements that require anchors and margins.

Spatial: Used only for 3D.

For more on making nodes, please see Making nodes.

Inheritance
Each node has several properties. Like Node with its name property, or Node2D with positional data. Every node that inherits it gains the properties of it. A brief example:


 * Node: name, script, others
 * Spatial: properties of Node; position; rotation; scale, others
 * CanvasItem: properties of Node; visibility; others
 * Node2D: properties of CanvasItem and of Node; position; rotation; scale; others
 * Control: properties of CanvasItem and of Node; rect position, size and scale; rotation; others
 * properties of Control, CanvasItem and Node; color

SceneTree
Godot has building blocks, yes, but what's the glue that sticks it all together?

The SceneTree is the glue, and it's a strong glue. But it is also a flexible glue. It is an  (which is the great-great grandfather/mother of all Godot "things").

The SceneTree is where everything happens. Nodes process in a certain order, draw on the screen, and more.

When making your game, each menu, every level, and every object are all scenes. You save them on the file system (or "fs" for short), and can then put those scenes within scenes. You could make an enemy scene, save it, then put it in your "level 1" scene as many times as you like. This is called instancing a scene.

Inheriting a scene can be considered the opposite to instancing. An inherited scene is like a copy of a scene, but with limited freedom to make modifications. This is useful to have a base enemy scene, then inherit it for each enemy you add, and make your modifications. This keeps your enemies consistent, and makes each file easier to understand. This is quite similar to inheriting a node, except that multiple nodes are inherited instead of making a new inherited script.

If, for example, on "Level 6", you have to fight a mutant version of a common enemy found throughout the game. You want to use it only once in the entire game, so is not worth inheriting the enemy scene and making a whole new file for an enemy used only once. Instead, while on level 6, right click on the enemy you want to modify in the Scene dock. Check the "editable children" box, and make your modifications. It is almost exactly the same as inheriting the scene, except that you are not making a new file.

If you decide that the mutant enemy would do well on other levels, or you use it more than once in a single level, left click on the enemy on the Scene dock and click "save branch as scene". This will save the node as a scene a with your modifications to be reused on any other level.

Adding a node
Okay, so now you know what you can do, how do you do any of it?

Lets create a simple scene. Open the Godot project manager. On the left is a list of buttons. Click New Project. A popup should appear. Press Browse under "Project Path:" and choose what folder to store your game. It's a good idea to have all your games in the same folder so they can be easily accessed. Once that is done, press "Create Folder", type something like "Godot test project", and click OK. Then click "Select Current Folder", and.

Now Godot should open. On the left, there should be a Scene dock with a few buttons on it. Click. Double click the bit that says "Control" and rename it to.



Now, press the white "+" icon in that dock, and a popup should appear. In the search bar, type. Double click the highlighted menu item for.

On the left, in the Inspector dock, look for the property. Type  (Make sure your Label is selected on the Scene dock). At the top of the screen is a  button. Click it. A drop down menu will appear with many options. Press Center. The "Hello world!" text appears at the center of the blue box in the 2D viewport (the large bit in the middle of the editor).



Now you know how to add a node, how do you delete them if you make a mistake? The fastest way is to undo (press "Control+z" on Windows). If the node is not recently created, instead left-click on it in the Scene dock. Click. If you delete a node you didn't want to delete, just press undo. If you press undo too many times, you can redo ("Control+Shift+Z" on Windows).

Now save your scene with "Control+S". Don't change the file name. You can also save to a different scene with "Control+Shift+S".

Instancing and editable children
To save a node and its children as a separate scene file, left click on the node and click. For this experiment, do so on your Label. The file name should be. Press "Save".



Find your Label scene but do not open it. Drag and drop it over your "Test UI" node in the Scene dock. At first it appears on the dock, but not on the viewport. This is because both Labels are on top of each-other. Click on your second Label in the Scene dock and click the move button at the top of the screen (or press w). Drag in any direction to see the new Label.



Open the  scene and and add another Label as a child of the root node (which should also be a label). Change the text property to "Label number 2". Save the scene. Go back to the  scene and notice how both the new and old labels overlap? Go back to the Label scene, select the second Label and move it down by clicking "Shift+Down arrow" 5 times. Save. Go to the other scene. Both Label scenes display correctly, not just one.



On the second label in your scene, left click and check. Click the gray Label button (the child of the second Label), and change it's text property to "Edited child". The other Label and the  scene were not changed, but one you changed was.

Right click on the Label with editable children and press. Now the modified label scene is no-longer linked, you can do some finer tweaking like renaming the child or deleting it. You can play around with your new scenes, or continue on.



What you have learned

 * 1) What nodes are in Godot and how to use each of the three basic ones.
 * 2) How to instance a scene into another, and how to save existing nodes into a new Scene.
 * 3) About node inheritance.
 * 4) How to start a new project.

Quiz


{Name one of the three main node types: } { Node|Node2D|Control|CanvasItem|Spatial|node|node2d|control|canvasitem|spatial }
 * type="{}"

{Do editable children allow you to edit the original scene? } -Yes +No
 * type=""

{Can you can instance a scene from another scene, then instance that scene from two different ones? } +Yes -No
 * type=""
 * That's what makes Godot's scene system flexible

{Which of these are the one that all the others inherit? } -Node +Object -SceneTree -CanvasItem
 * type=""

