What is GDExtension?

Introducción

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

Nota

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.

Ambos también te permiten integrar bibliotecas de terceros en Godot. La elección entre ellos depende de tus necesidades específicas.

Advertencia

GDExtension actualmente es experimental, lo que significa que podríamos romper la compatibilidad para corregir errores importantes o incluir características críticas.

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.

Tambien:

  • 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 runtime.

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

Ventajas de los módulos de C++

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

  • Los módulos de C++ proporcionan una integración más profunda con el motor. El acceso de GDExtension no es tan profundo como módulos estáticos.

  • Puedes utilizar módulos de C++ para proporcionar características adicionales en un proyecto sin tener que llevar archivos de bibliotecas nativas. Esto se extiende también a los proyectos exportados.

Nota

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.

Lenguajes soportados

The Godot developers officially support the following language bindings for GDExtension:

Nota

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

Los enlaces a continuación son desarrollados y mantenidos por la comunidad:

Nota

No todos los enlaces mencionados aquí pueden estar listos para producción. Asegúrate de investigar exhaustivamente las opciones antes de comenzar un proyecto con alguno de ellos. Además, verifica si el enlace es compatible con la versión de Godot que estás utilizando.

Compatibilidad de versiones

Usually, 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.

For this reason, when creating GDExtensions, you may want to target the lowest version of Godot that has the features you need, not the most recent version of Godot. This can save you from needing to create multiple builds for different versions of Godot.

Sin embargo, GDExtension se encuentra actualmente en fase experimental, lo que significa que podríamos romper la compatibilidad para corregir errores importantes o incluir funciones críticas. Por ejemplo, las GDExtensions creadas para Godot 4.0 no son compatibles con Godot 4.1 (véase Actualizando su GDExtension para la versión 4.1).

GDExtensions are also only compatible with engine builds that use the same level of floating-point precision the extension was compiled for. This means that if you use an engine build with double-precision floats, the extension must also be compiled for double-precision floats and use an extension_api.json file generated by your custom engine build. See Coordenadas de mundo extenso for details.

Generally speaking, if you build a custom version of Godot, you should generate an extension_api.json from it for your GDExtensions, because it may have some differences from official Godot builds.