一键导入
godot-gdextension
GDExtension specialist for C++/Rust native bindings, custom nodes, high-performance modules, and native code integration with Godot 4.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
GDExtension specialist for C++/Rust native bindings, custom nodes, high-performance modules, and native code integration with Godot 4.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
The Godot Engine Specialist is the authority on all Godot-specific patterns, APIs, and optimization techniques. Guides C# (primary) vs GDScript (optional) vs GDExtension decisions, ensures proper use of Godot's node/scene architecture, signals, and resources.
快速恢复项目上下文 — 新会话中读取已有配置,无需重新走 /start 流程。
First-time onboarding — asks where you are, then guides you to the right workflow. No assumptions.
引导式美术圣经编写。创建视觉规范文档,作为所有资产制作的基础。在 /brainstorm 完成后、/map-systems 或 GDD 编写之前运行。
美术与程序协调桥梁。处理资产规格、命名规范、导入管道和美术-程序沟通。
从 GDD、关卡文档或角色档案生成资产规格。包含 AI 图像生成提示词和详细规格。在美术圣经和 GDD 批准后、制作开始前运行。
| name | godot-gdextension |
| description | GDExtension specialist for C++/Rust native bindings, custom nodes, high-performance modules, and native code integration with Godot 4. |
| license | MIT |
This skill provides expert guidance for creating native extensions in Godot 4 using C++, Rust, or other languages via GDExtension.
Use this skill when:
GDExtension allows:
| Use GDScript | Use GDExtension |
|---|---|
| Game logic, state | Heavy math (physics, pathfinding) |
| UI, scene management | Procedural generation |
| Standard gameplay | >1000 calls/frame operations |
| Prototyping | Native library integration |
| Most game code | Custom rendering pipelines |
project/
├── src/ # GDScript source
├── native/ # GDExtension source
│ ├── include/ # Header files
│ ├── src/ # Implementation
│ ├── SConstruct # SCons build script
│ └── .gdextension # Extension config
└── addons/
└── my_extension/ # Compiled extension
├── bin/
│ ├── my_extension.dll # Windows
│ ├── my_extension.so # Linux
│ └── my_extension.dylib # macOS
└── my_extension.gdextension
[configuration]
entry_symbol = "my_extension_library_init"
compatibility_minimum = "4.2"
[libraries]
windows.debug.x86_64 = "res://addons/my_extension/bin/my_extension.dll"
windows.release.x86_64 = "res://addons/my_extension/bin/my_extension.dll"
linux.debug.x86_64 = "res://addons/my_extension/bin/my_extension.so"
linux.release.x86_64 = "res://addons/my_extension/bin/my_extension.so"
macos.debug = "res://addons/my_extension/bin/my_extension.dylib"
macos.release = "res://addons/my_extension/bin/my_extension.dylib"
#ifndef MY_NODE_HPP
#define MY_NODE_HPP
#include <godot_cpp/classes/node.hpp>
#include <godot_cpp/core/class_db.hpp>
namespace my_extension {
class MyNode : public godot::Node {
GDCLASS(MyNode, godot::Node)
private:
double custom_value;
protected:
static void _bind_methods();
public:
MyNode();
~MyNode();
void _process(double delta) override;
void set_custom_value(double value);
double get_custom_value() const;
};
} // namespace my_extension
#endif // MY_NODE_HPP
#include "my_node.hpp"
namespace my_extension {
void MyNode::_bind_methods() {
godot::ClassDB::bind_method(godot::D_METHOD("set_custom_value", "value"), &MyNode::set_custom_value);
godot::ClassDB::bind_method(godot::D_METHOD("get_custom_value"), &MyNode::get_custom_value);
ADD_PROPERTY(godot::PropertyInfo(godot::Variant::FLOAT, "custom_value"), "set_custom_value", "get_custom_value");
}
MyNode::MyNode() : custom_value(0.0) {}
MyNode::~MyNode() {}
void MyNode::_process(double delta) {
// High-performance processing here
}
void MyNode::set_custom_value(double value) {
custom_value = value;
}
double MyNode::get_custom_value() const {
return custom_value;
}
} // namespace my_extension
#include "register_types.hpp"
#include "my_node.hpp"
#include <godot_cpp/core/class_db.hpp>
#include <godot_cpp/core/defs.hpp>
#include <godot_cpp/godot.hpp>
namespace my_extension {
void initialize_my_extension_module(godot::ModuleInitializationLevel p_level) {
if (p_level != godot::MODULE_INITIALIZATION_LEVEL_SCENE) {
return;
}
godot::ClassDB::register_class<MyNode>();
}
void uninitialize_my_extension_module(godot::ModuleInitializationLevel p_level) {
if (p_level != godot::MODULE_INITIALIZATION_LEVEL_SCENE) {
return;
}
}
} // namespace my_extension
extern "C" {
GDExtensionBool GDE_EXPORT my_extension_library_init(
GDExtensionInterfaceGetProcAddress p_get_proc_address,
GDExtensionClassLibraryPtr p_library,
GDExtensionInitialization *r_initialization
) {
godot::GDExtensionBinding::InitObject init_obj(p_get_proc_address, p_library, r_initialization);
init_obj.register_initializer(initialize_my_extension_module);
init_obj.register_uninitializer(uninitialize_my_extension_module);
init_obj.set_minimum_library_initialization_level(godot::MODULE_INITIALIZATION_LEVEL_SCENE);
return init_obj.init();
}
}
[package]
name = "my_godot_extension"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib"]
[dependencies]
godot = { git = "https://github.com/godot-rust/gdext" }
[profile.release]
opt-level = 3
lto = "thin"
use godot::prelude::*;
#[derive(GodotClass)]
#[class(base=Node3D)]
struct TerrainGenerator {
base: Base<Node3D>,
#[export]
chunk_size: i32,
#[export]
seed: i64,
}
#[godot_api]
impl INode3D for TerrainGenerator {
fn init(base: Base<Node3D>) -> Self {
Self {
base,
chunk_size: 64,
seed: 0
}
}
fn ready(&mut self) {
godot_print!("TerrainGenerator ready");
}
}
#[godot_api]
impl TerrainGenerator {
#[func]
fn generate_chunk(&self, x: i32, z: i32) -> Dictionary {
// Rust 中执行重计算
let mut result = Dictionary::new();
// ... 大量计算 ...
result
}
}
关键: GDExtension 二进制文件在 Godot 次版本之间不兼容:
.gdextension 无法在 Godot 4.4 中运行.gdextension 文件中的 compatibility_minimum 必须匹配项目目标版本在建议任何 GDExtension 模式前:
docs/engine-reference/godot/VERSION.md 确认引擎版本breaking-changes.md 了解可能影响原生绑定的变更# SConstruct
SConscript("godot-cpp/SConstruct")
env = SConscript("godot-cpp/SConstruct")
env.Append(CPPPATH=["#include"])
env.Append(LIBPATH=["godot-cpp/bin"])
sources = Glob("src/*.cpp")
library = env.SharedLibrary(
"bin/my_extension",
source=sources,
SHLIBSUFFIX=".dll" # Adjust for platform
)
cargo build --release
# Output in target/release/my_godot_extension.dll
// ✅ 正确 — 后台线程计算,主线程应用
std::thread worker([this]() {
auto results = heavy_computation();
call_deferred("apply_results", results);
});
// ❌ 错误 — 从后台线程访问场景树
std::thread worker([this]() {
add_child(node); // 崩溃!场景树只能在主线程操作
});
double 而非 VariantRef<T> — 理解引用计数godot::prelude::* — 只导入需要的GDScript 拥有: 游戏逻辑、场景管理、UI、高层协调
Native 拥有: 重计算、数据处理、性能关键热路径
接口: Native 暴露节点、资源、GDScript 可调用的函数
数据流: GDScript 调用 Native 方法 → Native 计算 → 返回结果
Ref<T> / Gd<T>(生命周期问题)| 错误 | 修正 |
|---|---|
| .gdextension 中 Godot 版本不匹配 | 确保 compatibility_minimum 正确 |
缺少 entry_symbol 配置 | 添加入口符号配置 |
| 错误的库路径格式 | 使用平台特定路径 |
| 类未正确注册 | 使用 ClassDB::register_class<T>() |
| 忽略引用计数 | 理解 Ref<T> 和 Gd<T> |
| 过度使用 Variant | 优先使用类型化参数 |
| 未处理线程安全 | 使用 call_deferred() |