Skip to main content

Overview

GDExtension is Godot’s system for creating native extensions using C++ or other compiled languages. It provides a C API for extending Godot’s functionality with high-performance code while maintaining full engine integration.
GDExtension replaces GDNative from Godot 3.x with improved performance, better compatibility, and easier development.

Why Use GDExtension?

Maximum performance

Native compiled code for CPU-intensive algorithms, physics, and AI.

Existing C++ libraries

Integrate third-party C++ libraries directly into Godot.

Platform-specific code

Access platform APIs and SDKs not exposed by Godot.

Reusable modules

Share compiled extensions across projects without source code.

Getting Started

Prerequisites

1

Install a C++ compiler

Windows: Visual Studio 2019+ or MinGW-w64macOS: Xcode Command Line ToolsLinux: GCC or Clang
2

Install SCons build system

3

Clone godot-cpp

4

Build godot-cpp

Replace <platform> with: windows, linux, macos, android, or ios

Project Structure

A typical GDExtension project structure:

Creating Your First Extension

1. Define a Custom Class

my_class.h

2. Implement the Class

my_class.cpp

3. Register the Extension

register_types.h
register_types.cpp

4. GDExtension Configuration

Create my_extension.gdextension:
my_extension.gdextension

5. Build Configuration (SConstruct)

SConstruct

6. Build the Extension

Using Your Extension in Godot

In GDScript

In C#

Advanced Features

Working with Godot Types

Resource Management

Calling Godot Singletons

Performance Benefits

GDExtension provides near-native C++ performance, often 10-100x faster than GDScript for CPU-intensive operations.

Debugging

Native Debugger

Attach a C++ debugger to the running Godot process:
  1. Build with debug symbols (target=template_debug)
  2. Run Godot
  3. Debug → Attach to Process
  4. Select the Godot process
  5. Set breakpoints in your C++ code

Platform-Specific Code

Best Practices

Profile first

Only use GDExtension for proven performance bottlenecks. GDScript is sufficient for most game logic.

Clear API boundaries

Design clean interfaces between GDScript and C++ code.

Error handling

Validate input from GDScript. Check for null pointers and invalid data.

Memory management

Use Godot’s reference counting (Ref<T>) for resources. Don’t use raw new/delete.

Build for all platforms

Test your extension on all target platforms early.

Documentation

Document your C++ API thoroughly for GDScript users.
Common pitfalls:
  • Memory leaks from improper reference counting
  • Crashes from null pointer dereference
  • Thread safety issues when accessing Godot APIs
  • Platform-specific bugs from untested code paths

Language Bindings

GDExtension isn’t limited to C++. Community bindings exist for: Each provides idiomatic APIs for their respective languages.

Example: Rust GDExtension

Next Steps

GDScript

Learn Godot’s built-in scripting language

C# Scripting

Use C# for managed code with .NET

godot-cpp Repository

Official C++ bindings repository

Performance Optimization

Learn more about optimizing Godot games