Nodes are Godot’s fundamental building blocks. Everything in your game is built from nodes organized into scene hierarchies. Understanding how nodes and scenes work is essential to mastering Godot.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/godotengine/godot/llms.txt
Use this file to discover all available pages before exploring further.
What is a Node?
A Node is the base class for all scene objects in Godot. Nodes can be assigned as children of other nodes, creating a tree structure. Each node can contain any number of child nodes, with the requirement that all siblings (direct children of a node) have unique names.Nodes inherit from the
Object class, giving them access to signals, properties, and methods that form the foundation of Godot’s object system.Node Hierarchy
Nodes are organized in a parent-child relationship:What is a Scene?
A scene is a tree of nodes saved together. Scenes can be saved to disk and then instantiated into other scenes, allowing for highly flexible and modular game architecture.Creating Scenes Programmatically
The
owner property determines which nodes get saved when packing a scene. Only nodes with their owner set will be included in the saved scene file.Instancing Scenes
One of the most powerful features of scenes is the ability to instance them multiple times:Node Lifecycle
Nodes go through a specific lifecycle when added to or removed from the scene tree.Entering the Tree
When a node is added to the scene tree:
- The parent’s
_enter_tree()is called first - Then children’s
_enter_tree()methods are called in order - The node receives
NOTIFICATION_ENTER_TREE
Ready Notification
After all nodes have entered the tree:
- Children’s
_ready()methods are called first (bottom-up) - Then the parent’s
_ready()is called - The node receives
NOTIFICATION_READY
Processing Callbacks
Nodes can receive processing callbacks on each frame to update their state.Process Callback
The_process() callback runs on every frame and is ideal for game logic, animations, and visual updates:
Physics Process Callback
The_physics_process() callback runs at a fixed rate (60 Hz by default) and should be used for physics-related code:
By default,
_physics_process() is called 60 times per second, regardless of the visual framerate. This ensures consistent physics behavior.Managing Nodes
Adding and Removing Children
Finding Nodes
Node Paths
Node paths are used to reference nodes in the scene tree:Parent-Child Relationships
Practical Example: Building a Game Object
Here’s a complete example of creating a player character scene:Understanding @onready
Understanding @onready
The
@onready annotation defers variable initialization until _ready() is called. This ensures that child nodes are available when you try to access them:Best Practices
Use Scenes for Reusable Components
Create separate scene files for game objects you’ll use multiple times (enemies, bullets, UI elements, etc.).
Keep Hierarchies Organized
Use descriptive names and organize nodes logically. Group related nodes under parent nodes.
Set Owner When Creating Nodes
When creating nodes programmatically that you want to save, always set the
owner property.Use queue_free() Over free()
Prefer
queue_free() to safely delete nodes at the end of the current frame, avoiding potential errors.Next Steps
Signals
Learn how nodes communicate using Godot’s signal system
Scene Tree
Understand how the SceneTree manages your game