Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

What is GDExtension?

前言

GDExtension is a Godot-specific technology that lets the engine interact with native shared libraries at run-time. You can use it to run native code without compiling it with the engine.

备注

GDExtension is not a scripting language and has no relation to GDScript.

Differences between GDExtension and C++ modules

You can use both GDExtension and C++ modules to run C or C++ code in a Godot project.

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

备注

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 to expose the missing functionality.

Advantages of 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 is not limited to C and C++. Thanks to third-party bindings, you can use it with many other languages.

  • 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++ 模块的优势

We recommend C++ modules in cases where GDExtension isn't enough:

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

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

支持的语言

The Godot developers officially support the following language bindings for 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 版本兼容。

版本兼容性

GDExtension add-ons compiled for a given Godot version are only guaranteed to work with the same minor release series. For example, a GDExtension add-on compiled for Godot 4.0 will only work with Godot 4.0, 4.0.1, 4.0.2. In addition, GDExtension is not compatible with Godot 3.x.