协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
access lazily; prefer `@onready` var to cache paths.\n- Grouping: `add_to_group(\"enemies\")`, iterate with `get_tree().get_nodes_in_group(\"enemies\")`.\n\n## 3. Scripting: GDScript vs C# vs GDExtension\n\n| Option | Use case |\n|--------|----------|\n| GDScript | Default: rapid iteration, tight editor integration, Python-like |\n| C# | Teams familiar with .NET; heavier runtime; good for tool-heavy projects |\n| GDExtension (C++/Rust) | Engine-critical hot loops; custom servers; portability |\n\n### 3.1 GDScript Rules\n\n- Typed where possible: `@export var speed: float`. Untyped variables run slower.\n- Hot loops: avoid string parsing, dynamic typing; use `const`.\n- `for i in count`: prefer typed loop counters.\n- Signal-based communication instead of polling.\n- `await` for async (timers, HTTP, animations).\n\n## 4. Rendering\n\n### 4.1 Backends\n\n| Backend | Use |\n|---------|-----|\n| **Forward+** | Desktop/console default; clustered lights, SSAO, SSR, volumetrics only in 4.3+ |\n| **Mobile** | Mobile; limited lights/volumetrics |\n| **Compatibility** | OpenGL 3.3; broadest device support (web, old hardware) |\n\n### 4.2 2D Rendering\n\n- CanvasItems with textures; use `Texture2D`, `AtlasTexture`, `AnimatedSprite2D`.\n- `y_sorted = true` for top-down sorting.\n- Use `Parallax2D` and `TileMapLayer` for levels.\n- 2D lights are optional per-renderer; provable cheap with `unshaded` materials.\n\n### 4.3 3D Rendering\n\n- Nodes: `MeshInstance3D`, `Camera3D`, `DirectionalLight3D`.\n- Standard materials: `StandardMaterial3D`, or `ShaderMaterial` with `gdshader`.\n- GPU particles via `GPUParticles3D` / 2D.\n- Use LightmapGI for static GI; keep dynamic lights under a handful on mobile.\n\n### 4.4 Shaders (Godot Shader Language)\n\n```glsl\nshader_type spatial;\nuniform vec4 tint : source_color = vec4(1.0);\nvoid fragment() {\n ALBEDO = texture(SCREEN_TEXTURE, SCREEN_UV).rgb * tint.rgb;\n}\n```\n\n- Run on GPU; for per-object control use uniforms + `MaterialOverride`.\n- Keep fragment cost low; use `hint_range` uniforms to let artists clamp.\n- `shader_type canvas_item` for 2D.\n\n## 5. Physics\n\n- **GodotPhysics3D/2D**: built-in, stable default.\n- **Jolt Physics** (Godot 4.4+): optional external, more realistic + fast.\n- Nodes: `CharacterBody3D`, `RigidBody3D`, `StaticBody3D`, `Area3D`, plus sensors.\n- Character movement via `move_and_slide()` / `move_and_collide()`.\n- Area3D triggers: `body_entered`/`body_exited` for pickup/trigger zones.\n- Layers & masks (`collision_layer`/`collision_mask`) control which bodies collide with what.\n\n### 5.1 Fixed Timestep\n\n`Engine.physics_ticks_per_second` default 60. Determinism: avoid unordered maps in physics callbacks; deterministic float ops across platforms require careful design (Jolt note).\n\n## 6. Animation\n\n- `AnimationPlayer` + `Animation` resources: animate any `Property` (position, color, shader).\n- `AnimationTree`: blend trees, state machines.\n- Tween API for simple tweens: `tween_property(node, \"position\", Vector2(...), 0.5)`.\n- Match with `create_tween().tween_interval(duration)`.\n\n## 7. UI (Control Nodes)\n\n- `Control` nodes form anchored layout; `MarginContainer`, `VBoxContainer`, `GridContainer`.\n- Build UI in editor or code: `preload(\"res://ui/hud.tscn\").instantiate()`.\n- Signals: `button.pressed.connect(_on_pressed)`.\n- Use `CanvasLayer` for screen-space (HUD) that ignores camera.\n\n## 8. Multiplayer\n\n- High-level API (`SceneMultiplayer`) with `spawn(_path)` and `rpc()` calls for data sync.\n- `MultiplayerSynchronizer` / `MultiplayerSpawner` to sync properties per peer.\n- `Server` authoritative pattern; `Authority` via `set_multiplayer_authority`.\n- `rpc_id(id, \"func\", args)` for targeted messages; `rpc` broadcasts.\n\n### 8.1 Prediction/Reconciliation\n\nGodot high-level API is simple but not prediction-ready; implement manual `RigidBody3D` + `MultiplayerSynchronizer` interpolation on clients for smooth netcode.\n\n## 9. Asset Pipeline & Tooling\n\n- `.tscn` text scenes (versionable), `.tres` resources.\n- Import pipeline at `res://` (Godot imports on editor build).\n- `ResourceLoader` / `preload` (compile-time) vs `load` (async `ResourceLoader.load_threaded_request`).\n- Remote debugger, GDScript debugger, Visual Profiler, Frame Profiler baked into editor.\n\n## 10. Performance Rules\n\n- Profile with built-in profiler + `Engine.get_frames_per_second()`.\n- Avoid `_process` for nodes that don't change.\n- Pool bullets/enemies (no instantiate/free per shot).\n- Pre-load large scenes once; `duplicate()` cached resources.\n- Trap: `get_node(\"./long/path\")` every frame → cache in `@onready`.\n- Light count: keep 3D dynamic lights \u003c 8 (mobile) / \u003c 32 (desktop).\n- Use `limiting draw` culling: `camera cull_mask`, `visibility_notifier` (VisibilityNotifier3D).\n\n### 10.1 Node Count Toggle\n\nFor thousands of simple nodes prefer a single `_draw()`-heavy `Control`/`CanvasItem` drawing primitives, or render via `MeshInstance3D` instancing (`MultiMesh`).\n\n## 11. Anti-Patterns\n\n| Anti-pattern | Consequence | Fix |\n|--------------|-------------|-----|\n| GetNode per frame | String path lookups | @onready cache |\n| Untyped variables in loops | Slow | typed loops |\n| Instantiate/free each shot | GC/alloc spikes | object pool |\n| All nodes `_process` ticking | CPU | disable unused |\n| Many dynamic lights | mobile GPU melt | baked lightmap + clip |\n| Async without `await` | deadlock/race | `await` signal |\n\n## 12. When to NOT Use Godot\n\n- Extremely large open worlds with heavy asset streaming → Unreal/Unity.\n- Console-specific (Xbox-only) native integrations → engine with first-class console SDK support (Unreal/Unity).\n- Browser tiny canvas games → Phaser / vanilla canvas (lighter).\n- Deep custom rendering/engine platform → Vulkan/custom.\n\n## 13. References\n\n- `skills/game/game-development/godot-gdscript/SKILL.md` — Godot server architecture + GDScript deep dive\n- `skills/game/game-engine/ecs-pattern/SKILL.md` — ECS patterns for scale\n- `skills/game/game-engine/patterns/SKILL.md` — engine design patterns\n- `skills/game/multiplayer-netcode/SKILL.md` — netcode for the high-level API\n- `skills/game/game-development/physics-engine/SKILL.md` — physics internals (Jolt/GodotPhysics)","licenseDocuments":[]}}
godot【开发与工程】Expert game development with Godot Engine - nodes and scenes, GDScript/C#/GDExtension, the renderer (Forward+/Mobile/Compatibility), physics (GodotPhysics/Jolt), animation, UI (Control), and performance.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Godot is a free, open-source game engine built around a scene-tree of Nodes, a first-class editor, and a friendly scripting language (GDScript) plus optional C#, C++, and Rust via GDExtension. Its modular renderer supports Forward+, Mobile, and Compatibility backends.
Godot SceneTree
Scene (Node tree)
Node (base: name, owner, groups, tree refs)
Control -> UI (UI Toolkit equivalent)
Node2D -> 2D gameplay
Node3D -> 3D gameplay
... custom scripts attach via GDScript/C#/GDExtension
MainLoop -> SceneTree tick: process(delta) -> physics_process(delta)
_processextends Node
func _ready(): pass # once when entering tree
func _process(delta): pass # every rendered frame
func _physics_process(delta): pass # fixed 60Hz by default
func _input(event): pass # input events BEFORE process
func _unhandled_input(event): pass # input not consumed by UI
Rules:
_physics_process if using physics bodies; interpolate the visual Spatial/Node2D in _process.process_mode = PROCESS_MODE_DISABLED for nodes that don't act per-frame.Project Settings -> Autoload: one scene/script loaded globally. Use autoload game manager, audio bus, settings. Alternative to Object.get_node('/root/GameManager').
preload/load/instance().@export var speed: float = 10.0 exposes editable properties to the inspector.const Bullet = preload("res://scenes/bullet.tscn")
func fire():
var b = Bullet.instantiate()
b.position = muzzle.global_position
get_tree().get_root().add_child(b)
b.velocity = Vector2(speed, 0)
get_node/$ access lazily; prefer @onready var to cache paths.add_to_group("enemies"), iterate with get_tree().get_nodes_in_group("enemies").| Option | Use case |
|---|---|
| GDScript | Default: rapid iteration, tight editor integration, Python-like |
| C# | Teams familiar with .NET; heavier runtime; good for tool-heavy projects |
| GDExtension (C++/Rust) | Engine-critical hot loops; custom servers; portability |
@export var speed: float. Untyped variables run slower.const.for i in count: prefer typed loop counters.await for async (timers, HTTP, animations).| Backend | Use |
|---|---|
| Forward+ | Desktop/console default; clustered lights, SSAO, SSR, volumetrics only in 4.3+ |
| Mobile | Mobile; limited lights/volumetrics |
| Compatibility | OpenGL 3.3; broadest device support (web, old hardware) |
Texture2D, AtlasTexture, AnimatedSprite2D.y_sorted = true for top-down sorting.Parallax2D and TileMapLayer for levels.unshaded materials.MeshInstance3D, Camera3D, DirectionalLight3D.StandardMaterial3D, or ShaderMaterial with gdshader.GPUParticles3D / 2D.shader_type spatial;
uniform vec4 tint : source_color = vec4(1.0);
void fragment() {
ALBEDO = texture(SCREEN_TEXTURE, SCREEN_UV).rgb * tint.rgb;
}
MaterialOverride.hint_range uniforms to let artists clamp.shader_type canvas_item for 2D.CharacterBody3D, RigidBody3D, StaticBody3D, Area3D, plus sensors.move_and_slide() / move_and_collide().body_entered/body_exited for pickup/trigger zones.collision_layer/collision_mask) control which bodies collide with what.Engine.physics_ticks_per_second default 60. Determinism: avoid unordered maps in physics callbacks; deterministic float ops across platforms require careful design (Jolt note).
AnimationPlayer + Animation resources: animate any Property (position, color, shader).AnimationTree: blend trees, state machines.tween_property(node, "position", Vector2(...), 0.5).create_tween().tween_interval(duration).Control nodes form anchored layout; MarginContainer, VBoxContainer, GridContainer.preload("res://ui/hud.tscn").instantiate().button.pressed.connect(_on_pressed).CanvasLayer for screen-space (HUD) that ignores camera.SceneMultiplayer) with spawn(_path) and rpc() calls for data sync.MultiplayerSynchronizer / MultiplayerSpawner to sync properties per peer.Server authoritative pattern; Authority via set_multiplayer_authority.rpc_id(id, "func", args) for targeted messages; rpc broadcasts.Godot high-level API is simple but not prediction-ready; implement manual RigidBody3D + MultiplayerSynchronizer interpolation on clients for smooth netcode.
.tscn text scenes (versionable), .tres resources.res:// (Godot imports on editor build).ResourceLoader / preload (compile-time) vs load (async ResourceLoader.load_threaded_request).Engine.get_frames_per_second()._process for nodes that don't change.duplicate() cached resources.get_node("./long/path") every frame → cache in @onready.limiting draw culling: camera cull_mask, visibility_notifier (VisibilityNotifier3D).For thousands of simple nodes prefer a single _draw()-heavy Control/CanvasItem drawing primitives, or render via MeshInstance3D instancing (MultiMesh).
| Anti-pattern | Consequence | Fix |
|---|---|---|
| GetNode per frame | String path lookups | @onready cache |
| Untyped variables in loops | Slow | typed loops |
| Instantiate/free each shot | GC/alloc spikes | object pool |
All nodes _process ticking | CPU | disable unused |
| Many dynamic lights | mobile GPU melt | baked lightmap + clip |
Async without await | deadlock/race | await signal |
skills/game/game-development/godot-gdscript/SKILL.md — Godot server architecture + GDScript deep diveskills/game/game-engine/ecs-pattern/SKILL.md — ECS patterns for scaleskills/game/game-engine/patterns/SKILL.md — engine design patternsskills/game/multiplayer-netcode/SKILL.md — netcode for the high-level APIskills/game/game-development/physics-engine/SKILL.md — physics internals (Jolt/GodotPhysics)