gamedev-skills/awesome-gamedev-agent-skills

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.

查看源码

使用方法

  1. 复制安装命令,在自己的智能体环境安装前先检查源码包。
  2. 从原始文档核对所需工具、凭据和支持的宿主。
  3. 说明输入材料与期望交付物,并对照来源检查输出。
npx skills add https://github.com/gamedev-skills/awesome-gamedev-agent-skills --skill godot-nodes-scenes

开始前需了解

  • 安装不包含模型订阅、API 额度或访问文件的权限。
  • 仓库星数和安装量反映活跃情况,不等于独立质量或安全测试。
仓库原始内容

按源仓库内容呈现,保留标题、案例、代码、表格、链接以及原文引用的演示图片。

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.

  1. 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.

  1. Instance at runtime with preload/load → scene.instantiate() →

add_child(instance). Set position/state after adding (or before, both work).

  1. 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.

  1. Use autoloads for global state/services (game state, audio, scene switching) —

registered in Project Settings > Globals (Autoload), accessible by name everywhere.

  1. Free nodes with `queue_free()` and guard later access with is_instance_valid().
  2. 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

gdscript
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: $, getnodeor_null, and unique names

gdscript
@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)

gdscript
# 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

gdscript
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()` 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, 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, and get_tree().current_scene isn'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, 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.
来自同一仓库

更多 Skills

全部 Skills
gamedev-skills
社区

game-feel

Add "juice" and game feel that makes actions satisfying — screen shake, hit-stop/freeze frames, tweened/eased motion, squash & stretch, knockback, and layered audio-visual feedback — as engine-neutral techniques that pair with the detected engine's tween, particle, and camera APIs. Use when the user mentions game feel, juice, "make it feel good/punchy", screen shake, hit stop, screen freeze, easing, squash and stretch, impact frames, or feedback/polish on hits, jumps, pickups, and deaths.

安装量
16
GitHub Stars
4316
最近更新
10月24日
gamedev-skills
社区

audio-design

Implement game audio practice — bus/mixer architecture and gain in decibels, ducking (sidechain), adaptive/dynamic music via layering and re-sequencing, SFX variation, and beat synchronization. Engine-neutral. Use when the user mentions audio mixing, audio buses, adaptive/dynamic music, ducking, SFX variation, music layers, or syncing gameplay to the beat.

安装量
13
GitHub Stars
4316
最近更新
10月24日
gamedev-skills
社区

performance-optimization

Find and fix game performance problems methodically — measure with the engine profiler first, reason about the frame-time budget, locate the CPU-vs-GPU bottleneck, then apply the right fix: object pooling, draw-call batching, fewer allocations/GC spikes, and asset budgets. Engine- neutral method that pairs with each engine's profiler. Use when the user mentions performance, optimize, low/dropping FPS, frame drops, stutter, lag, profiler, frame budget, draw calls, batching, garbage collection/GC

安装量
13
GitHub Stars
4316
最近更新
10月24日
gamedev-skills
社区

shader-programming

Write game shaders from cross-engine fundamentals — the vertex→fragment pipeline, coordinate spaces, UV math, and common 2D/3D effects (tint, UV scroll, dissolve, outline, fresnel rim, vignette) in GLSL with HLSL equivalents. Use when the user mentions shaders, fragment/pixel shader, vertex shader, UV, GLSL, HLSL, or effects like dissolve, outline, or rim light.

安装量
13
GitHub Stars
4316
最近更新
10月24日