godot-nodes-scenes

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 aut

By gamedev-skills · 2,441 installs

npx skills add gamedev-skills/awesome-gamedev-agent-skills --skill godot-nodes-scenes

Source repository · Upstream listing

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 .tscn scenes, choosing how to break a feature into nodes, instancing a PackedScene (bullets, enemies, UI), or setting up autoload singletons. Use when debugging get node() / $Path returning null , 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 1. 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. 2. Make a scene reusable by giving its root a script and exposing @export config. Save it; it becomes a PackedScene you can instance many times. 3. Instance at runtime with preload / load → scene.instantiate() → add child(instance) . Set position/state after adding (or before, both work). 4. Access nodes safely. Use @onready var x = $Path for fixed children; use unique names ( %Name ) for nodes deep in the tree; never assume a node still exists. 5. Use autoloads for global state/services (game state, audio, scene switching) — registered in Project Settings Globals (Autoload), accessible by name everywhere. 6. Free nodes with queue free() and guard later access with is instance valid() . 7. Check references before you finish. After creating, moving or renaming scenes, resources or scripts, run python scripts/check godot project.py <project dir (no Godot install needed; json for machine readable output). Fix every ERROR (missing or wrong case res:// paths, undeclared ExtResource / SubResource ids, bad parent= paths, missing main scene or autoload) and re run until it exits 0. Warnings such as a stale path= that Godot still finds by uid are safe but worth fixing. Run the script path relative to this skill directory, or resolve the installed skill path first. It needs Python 3.10+ and nothing else, and it does not replace opening the project in Godot. Patterns 1. Instance a scene at runtime 2. Safe node access: $, get node or null, and unique names 3. An autoload singleton (global game state) 4. Change the running scene Pitfalls $Path / get node() return null or error when the path is wrong or the node isn't in the tree yet. Use @onready , verify the path matches the scene, or use get node or null() for optional nodes. Renaming a node breaks $Path . Use unique names ( %Name , set via right click Access as Unique Name) so deep references survive renames and reparenting. free() mid frame can crash other code still using the node. Prefer queue free() (deletes at end of frame) and check is 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 @onready vars 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 to instantiate() in Godot 4. preload runs at parse time (path must be constant); load runs at runtime (path can be a variable). change scene to file() is deferred, and the old scene leaves the tree at once. The outgoing scene is removed from the tree immediately (its get tree() now returns null , and get tree().current scene is null ), then at the end of the frame it is freed and the new scene is added. Code after the call must not touch get tree() from the old scene. To act on the new scene, do it from the new scene's ready() , or from an autoload with await get tree().scene changed (Godot 4.5+). change scene to node(node) (4.6+) swaps in a node you have already instanced and configured. References For scene inheritance, owner /ownership when saving scenes from code, groups vs unique names, and node path edge cases, read references/tree and instancing.md . scripts/check godot project.py — read only reference checker for a Godot 4.x project; help lists every check and the exit codes. 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.