GDExtension Notes
π GDExtension: Native High-Performance Code in Godot 4
GDExtension is Godot 4βs native plugin interface (the successor to Godot 3's GDNative). It allows you to write high-performance gameplay code, custom nodes, and engine extensions in C++, Odin, C, or Rustβcompiling them into a dynamic library (.dll / .so) that loads directly into the engine.
Crucially: You do not need to recompile the Godot engine binary to use native code.
π‘ Why Use GDExtension?
Coming from a C-style / systems programming perspective:
- Bare-Metal Speed: Eliminate VM overhead for CPU-heavy tasks like procedural terrain generation, flocking algorithms, custom raymarching, or custom pathfinding.
- Third-Party C/C++ Interop: Wrap native libraries directlyβsuch as
GameNetworkingSockets(from Basics Of NetWorking), custom DSP filters, or raw Vulkan extensions. - Seamless Editor Integration: Custom classes defined in GDExtension inherit from Godot's
NodeorResource, appear in the Editor's "Create New Node" dialog, and expose properties directly in the Inspector. - Hot Reloading: In Godot 4.x, GDExtension supports dynamic unloading and reloading while the editor runs, drastically shortening iteration time.
βοΈ Architecture: The C ABI & Bindings
+-------------------------------------------------------------+
| Godot Engine |
| Exposes C ABI: gdextension_interface.h |
+-------------------------------------------------------------+
|
(Stable C-Function Pointers)
v
+-------------------------------------------------------------+
| Language Binding Layer |
| godot-cpp (Official C++) | godot-odin (Odin Bindings)|
+-------------------------------------------------------------+
|
+-------------------------------------------------------------+
| User Native Code |
| Custom Node3D, Custom Resource, Custom Servers |
+-------------------------------------------------------------+
Godot exports an extension_api.json dump containing all engine classes, methods, and constants. Community or official binding generators parse this JSON and generate type-safe bindings for your language of choice.
π The .gdextension Manifest
To tell Godot where your compiled libraries live, you create a .gdextension text file in your project folder (e.g. res://bin/my_extension.gdextension):
[configuration]
entry_symbol = "my_extension_library_init"
compatibility_minimum = "4.2"
[libraries]
windows.debug.x86_64 = "res://bin/libmy_extension.windows.template_debug.x86_64.dll"
windows.release.x86_64 = "res://bin/libmy_extension.windows.template_release.x86_64.dll"
linux.debug.x86_64 = "res://bin/libmy_extension.linux.template_debug.x86_64.so"
linux.release.x86_64 = "res://bin/libmy_extension.linux.template_release.x86_64.so"
macos.debug = "res://bin/libmy_extension.macos.template_debug.dylib"
macos.release = "res://bin/libmy_extension.macos.template_release.dylib"
π§± Initialization Levels
During startup, Godot initializes extensions in distinct stages:
CORE: Very early engine startup (memory allocators, basic data types).SERVERS: AfterRenderingServer,PhysicsServer3D, etc. have spun up. Good for custom server-level subsystems.SCENE: (Most common) Standard gameplay nodes (Node,Node3D,Control,Resource).EDITOR: Editor-only plugins, custom inspectors, and gizmo plugins.
α Using Odin with GDExtension
Because Odin excels at C-interop (as noted in Contextless Procedures and Odin Types), writing a GDExtension in Odin is exceptionally natural:
- Export the entry procedure as
proc "c" (interface: { #GDExtensionInterface} , library: GDExtensionClassLibraryPtr, initialization: { #GDExtensionInitialization} ) -> b32. - Use Odin's
context = runtime_default_context()inside C entry callbacks. - Pass structs with
#alignandb32fields to match the C ABI exactly.
βοΈ GDExtension vs Unreal C++
| Feature | Godot 4 GDExtension | Unreal Engine C++ |
|---|---|---|
| Compilation Time | Fast (small single dynamic library) | Slow (full engine headers & UBT build) |
| Hot Reload | Native library unload / reload | Live Coding / Hot Reload |
| Engine Source Access | Not required for development | Source included / accessible |
| Portability | Drop .dll and .gdextension in project | Tied to engine modules & UBT targets |
π Related Notes
- Intro Into Gdscript β The high-level language paired with GDExtension.
- Godot Basics & Architecture β Understanding the SceneTree and low-level servers.
- Odin Programming Language Index β Modern systems programming language overview.
- Functions β Procedure overloading,
#by_ptr, andproc "c"interop. - Types β Sized types and alignment for native ABI interop.
- Index for Unreal β Unreal Engine C++ architecture comparison.
- Game Development Hub β Main game development hub.