Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

GDExtension 是什么?


GDExtension 是 Godot 专有的技术,可以让引擎在运行时与原生共享库交互。你可以通过它来执行原生代码,无需和引擎一同编译。


GDExtension 不是脚本语言,与 GDScript 无关。

GDExtension 与 C++ 模块的区别

GDExtension 和 C++ 模块都可以用于在 Godot 项目中执行 C 或 C++ 代码。

它们都可以用来将第三方库集成进 Godot。选用哪一个取决于你的需求。


Our long-term goal is that GDExtensions targeting an earlier version of Godot will work in later minor versions, but not vice-versa. For example, a GDExtension targeting Godot 4.2 should work just fine in Godot 4.3, but one targeting Godot 4.3 won't work in Godot 4.2.

However, GDExtension is currently experimental, which means that we may break compatibility in order to fix major bugs or include critical features. For example, GDExtensions created for Godot 4.0 aren't compatible with Godot 4.1 (see 将 GDExtension 更新到 4.1).

GDExtension 的优点

Unlike modules, GDExtension doesn't require compiling the engine's source code, making it easier to distribute your work. It gives you access to most of the API available to GDScript and C#, allowing you to code game logic with full control regarding performance. It's ideal if you need high-performance code you'd like to distribute as an add-on in the asset library.


  • GDExtension 并不仅限于 C 和 C++。得益于第三方绑定,你也可以在很多其他语言中使用。

  • You can use the same compiled GDExtension library in the editor and exported project. With C++ modules, you have to recompile all the export templates you plan to use if you require its functionality at run-time.

  • GDExtension only requires you to compile your library, not the whole engine. That's unlike C++ modules, which are statically compiled into the engine. Every time you change a module, you need to recompile the engine. Even with incremental builds, this process is slower than using GDExtension.

C++ 模块的优点

如果 GDExtension 无法满足要求,我们推荐使用 C++ 模块

  • C++ modules provide deeper integration into the engine. GDExtension's access is not as deep as static modules.

  • 使用 C++ 模块为项目提供额外功能,就可以免去携带原生库文件的麻烦。同样也适用于导出的项目。


If you notice that specific systems are not accessible via GDExtension but are via custom modules, feel free to open an issue on the godot-cpp repository to discuss implementation options for exposing the missing functionality.


Godot 开发者官方支持以下 GDExtension 语言绑定:


There are no plans to support additional languages with GDExtension officially. That said, the community offers several bindings for other languages (see below).



这里列出的绑定并不都能用于生产。请在新项目中使用前先做足调查。同时,请确定该绑定与你所使用的 Godot 版本兼容。


为特定版本 Godot 编译的 GDExtension 插件只保证能够在相同次要版本上可用。例如,为 Godot 4.0 版本编译的 GDExtension 插件只能用于 Godot 4.0、4.0.1、4.0.2……另外 GDExtension 与 Godot 3.x 不兼容。

GDExtension add-ons are also only compatible with engine builds that use the level of floating-point precision the extension was compiled for. This means that if you use a engine build with double-precision floats, the extension must also be compiled for double-precision floats. See 大世界坐标 for details.