godot-nodes-scenes
gamedev-skills/awesome-gamedev-agent-skills
Structure Godot 4.x games with scenes, nodes, and runtime instancing.
What is godot-nodes-scenes?
Compose games from reusable scenes and nodes, instance them at runtime, and safely navigate the scene tree. Use when designing .tscn scenes, spawning instances with instantiate(), setting up autoloads, or fixing node-access errors in Godot 4.x projects.
- Build reusable scenes as PackedScenes and instance them at runtime with instantiate()
- Access nodes safely using @onready, unique names (%), and get_node_or_null() to avoid null/freed-node errors
- Compose larger scenes from smaller single-purpose scenes using node hierarchy
- Register and use autoload singletons for global state, services, and scene switching
- Change running scenes with change_scene_to_file() or change_scene_to_packed()
- Guard freed nodes with is_instance_valid() and queue_free() for safe cleanup
How to install godot-nodes-scenes
npx skills add https://github.com/gamedev-skills/awesome-gamedev-agent-skills --skill godot-nodes-scenes- Godot 4.7 installed and a project created
- Basic familiarity with GDScript and the scene editor
How to use godot-nodes-scenes
- 1.Open or create a .tscn scene file in the Godot editor
- 2.Design your scene by adding child nodes and arranging them in the tree; save it as a PackedScene
- 3.In a script, preload the scene with const SCENE := preload("res://path.tscn")
- 4.Call scene.instantiate() to create an instance, set its properties, then add_child(instance) to place it in the tree
- 5.For fixed child nodes, use @onready var child = $ChildPath; for deep nodes, right-click and enable 'Access as Unique Name' to use %UniqueName
- 6.Register autoload singletons in Project Settings > Globals > Autoload, then access them by name from any script
- 7.Use get_node_or_null(path) or is_instance_valid(node) to safely check if nodes exist before accessing them
Use cases
- Spawn bullets, enemies, or UI panels at runtime by instancing preloaded scenes
- Set up a global GameState autoload to track score, inventory, or game progress across scenes
- Refactor a deeply nested scene tree using unique names (%Name) to make references rename-proof
- Debug 'node not found' or 'attempt to call on freed instance' errors by using safe access patterns
- Switch between level scenes without manually freeing the old tree
- Godot 4.x game developers structuring projects with scenes and nodes
- Programmers building reusable, composable game entities and UI prefabs
- Game designers setting up global state and autoload singletons
- Developers debugging scene-tree access errors and node lifecycle issues
godot-nodes-scenes FAQ
The node path is incorrect, the node hasn't been added to the tree yet, or it was freed. Verify the path matches the scene hierarchy, use @onready to defer access until _ready(), or use get_node_or_null() for optional nodes.
Use unique names: right-click a node in the scene tree, select 'Access as Unique Name', then reference it with %NodeName instead of $Path/To/Node. Unique names survive renames and reparenting.
Always use queue_free() — it deletes the node at the end of the frame, letting other code finish safely. free() deletes immediately and can crash code still using the node. Check is_instance_valid(node) before accessing a freed node.
_ready() runs after the node is added to the tree with add_child(). You can set exported properties before add_child(), but @onready variables won't be initialized until _ready() executes.
No — change_scene_to_file() is deferred and swaps scenes at the end of the frame. Code on the same line still runs against the old tree. Read new scene nodes from its _ready() or _enter_tree() instead.
Full instructions (SKILL.md)
Source of truth, from gamedev-skills/awesome-gamedev-agent-skills.
name: godot-nodes-scenes description: > Structure a Godot 4.7 project with the scene tree and node composition: build reusable scenes, instance PackedScenes at runtime, navigate the tree safely, and register autoload singletons. Use when designing .tscn scenes, deciding how to split nodes, spawning instances with instantiate(), wiring autoloads, or fixing "node not found"/freed-node errors in a Godot project.
Godot Nodes & Scenes (4.x)
Compose games from nodes and scenes, instance them at runtime, and access the tree without crashing on freed or missing nodes. Targets Godot 4.7.
When to use
- Use when structuring
.tscnscenes, choosing how to break a feature into nodes, instancing aPackedScene(bullets, enemies, UI), or setting up autoload singletons. - Use when debugging
get_node()/$Pathreturningnull, or "Attempt to call on a previously freed instance".
When not to use: GDScript language/syntax → godot-gdscript; signal-based
decoupling → godot-signals-groups; physics bodies/collisions → godot-physics.
Core workflow
- Model with composition. A scene is a tree of nodes saved as
.tscn. Build small, single-purpose scenes (Player, Bullet, Enemy) and compose larger scenes from them. Favor adding child nodes over deep inheritance. - Make a scene reusable by giving its root a script and exposing
@exportconfig. Save it; it becomes aPackedSceneyou can instance many times. - Instance at runtime with
preload/load→scene.instantiate()→add_child(instance). Set position/state after adding (or before, both work). - Access nodes safely. Use
@onready var x = $Pathfor fixed children; use unique names (%Name) for nodes deep in the tree; never assume a node still exists. - Use autoloads for global state/services (game state, audio, scene switching) — registered in Project Settings > Globals (Autoload), accessible by name everywhere.
- Free nodes with
queue_free()and guard later access withis_instance_valid().
Patterns
1. Instance a scene at runtime
extends Node2D
const BULLET := preload("res://bullet.tscn") # preload: loaded at compile time
func shoot(at: Vector2, dir: Vector2) -> void:
var bullet := BULLET.instantiate() # create an instance of the scene
bullet.global_position = at
bullet.direction = dir # set exported/public state
add_child(bullet) # now it's in the tree and runs
2. Safe node access: $, get_node_or_null, and unique names
@onready var label: Label = $UI/Label # $ is sugar for get_node("UI/Label")
@onready var health_bar: ProgressBar = %HealthBar # % = scene-unique name (rename-proof)
func update() -> void:
var optional := get_node_or_null("Maybe/Missing") # returns null instead of erroring
if optional:
optional.queue_free()
3. An autoload singleton (global game state)
# game_state.gd — add in Project Settings > Globals > Autoload as "GameState".
extends Node
var score := 0
signal score_changed(value: int)
func add_score(points: int) -> void:
score += points
score_changed.emit(score) # any scene can: GameState.score_changed.connect(...)
4. Change the running scene
func go_to_level_2() -> void:
# Swaps the current scene for another. Frees the old scene tree.
get_tree().change_scene_to_file("res://levels/level_2.tscn")
# Or, with a preloaded PackedScene:
# get_tree().change_scene_to_packed(LEVEL_2)
Pitfalls
$Path/get_node()returnnullor error when the path is wrong or the node isn't in the tree yet. Use@onready, verify the path matches the scene, or useget_node_or_null()for optional nodes.- Renaming a node breaks
$Path. Use unique names (%Name, set via right-clickAccess as Unique Name) so deep references survive renames and reparenting.
free()mid-frame can crash other code still using the node. Preferqueue_free()(deletes at end of frame) and checkis_instance_valid(node).- Setting child state before
add_child()is fine, but_ready()on the child only runs after it enters the tree — don't expect its@onreadyvars before that. - Autoload order matters: autoloads are added before the main scene, in list order. An autoload can't depend on the main scene existing yet.
instance()was renamed toinstantiate()in Godot 4.preloadruns at parse time (path must be constant);loadruns at runtime (path can be a variable).change_scene_to_file()is deferred, not immediate — Godot swaps and frees the old scene at the end of the current frame. Any code after the call still runs against the old tree, andget_tree().current_sceneisn't the new scene until next frame. Don't read the new scene's nodes on the same line; do it from the new scene's_ready().
References
- For scene inheritance,
owner/ownership when saving scenes from code, groups vs unique names, and node-path edge cases, readreferences/tree-and-instancing.md.
Related skills
godot-gdscript— language, lifecycle, and@onready.godot-signals-groups— decouple instanced scenes from their spawner.godot-resources— share data between instances without duplicating it.save-systems— persist scene/game state across runs.
Related skills
More from gamedev-skills/awesome-gamedev-agent-skills and the wider catalog.

godot-physics
Configure Godot 4.x physics bodies, collision layers/masks, overlap detection, and raycasts in 2D and 3D.

godot-resources
Design data-driven Godot 4.7 games with custom Resource classes and .tres/.res files.

godot-shaders
Write Godot 4.7 shaders (2D canvas_item and 3D spatial) with uniforms, TIME animation, and screen-reading.

godot-signals-groups
Decouple Godot 4.x gameplay with signals and node groups instead of hard-coded references.

godot-tilemap
Build and edit tile-based 2D levels in Godot 4.7 with TileMapLayer, collision, terrains, and runtime cell manipulation.

godot-ui-control
Build responsive Godot 4.7 UIs with Control nodes, Containers, Themes, and keyboard/gamepad focus.