NodePath & @onready
Reference nodes efficiently with @onready and NodePath. Best practices for node access in GDScript.
Scripting
No shortcutBeginner7 min readQuick Reference
NodePath & @onready
Godot EngineKeyboard Shortcut
N/A
Where to Find
Select any node → Click Attach Script button, or Script Editor panel
Best Used For
- ▸Write game logic with variables and functions
- ▸Connect nodes via signals for decoupled systems
- ▸Expose Inspector properties for designer tweaking
Beginner-Friendly⏱ 15–30 minutes to master
Key Settings
@onready:NodePath:Relative paths:Absolute paths:
NodePath and @onready provide efficient ways to reference nodes in GDScript. Using @onready caches node references after the scene tree is ready, avoiding repeated get_node() calls.
Where to Find It
Use in any GDScript attached to a node. The @onready keyword is available in all scripts.
How to Use
- @onready:
@onready var sprite = $Sprite2Dfor cached references. - NodePath:
@export var target: NodePathfor Inspector-linked references. - Relative paths: Use
$NodeName/ChildNamefor relative paths. - Absolute paths: Use
%UniqueNamewith unique name access.
Pro Tips
- Always use @onready for node references — it is more performant than calling get_node() repeatedly.
- Use unique names (%) for cleaner references in complex scenes.