2
0

C++ bindings for the Godot script API

David Snopek 863d732f44 Merge pull request #1912 from dsnopek/dont-reload-print-error 3 өдөр өмнө
.github ce18d99cb0 Add back support for Godot 4.3 2 долоо хоног өмнө
cmake ce18d99cb0 Add back support for Godot 4.3 2 долоо хоног өмнө
gdextension 58d1de720b gdextension: Sync with upstream commit 89cea143987d564363e15d207438530651d943ac (4.6-stable) 4 өдөр өмнө
include 3a435c2248 Removed unused variable 1 долоо хоног өмнө
misc fe68c22c3e Generate GDExtension interface header and loader from JSON 1 сар өмнө
src 6d69a6219a Don't reuse the same list for `_get_property_list()` 1 долоо хоног өмнө
test ce18d99cb0 Add back support for Godot 4.3 2 долоо хоног өмнө
tools ce18d99cb0 Add back support for Godot 4.3 2 долоо хоног өмнө
.clang-format 64cdf089d9 CI: Various version bumps; sync with main repo 9 сар өмнө
.editorconfig 64cdf089d9 CI: Various version bumps; sync with main repo 9 сар өмнө
.gdignore f99aa47581 Add .gdignore file to godot-cpp, for use as submodule in Godot projects 3 жил өмнө
.git-blame-ignore-revs c963321cdd Ignore `#pragma once` commit 10 сар өмнө
.gitattributes 7a96d0314e Add `.editorconfig`, consolidate `.gitattributes` 1 жил өмнө
.gitignore 8534e2104f Modernise Existing CMakeLists.txt 1 жил өмнө
.gitmodules c4f12ccc3c Remove godot-headers submodule, copy files directly 3 жил өмнө
.pre-commit-config.yaml fe68c22c3e Generate GDExtension interface header and loader from JSON 1 сар өмнө
CMakeLists.txt c7873e1355 Migrate cmake docs to the godot docs. 3 сар өмнө
LICENSE.md 931f1a3f34 Sync license copyright with upstream GH-70885 3 жил өмнө
Makefile 67c9b2f8f4 Update Makefile after recent buildsystem changes 3 жил өмнө
README.md 6e47919ff8 Update README for versioning and compatibility changes in v10 2 долоо хоног өмнө
SConstruct 6a870949a5 Merge pull request #1669 from Ivorforce/scons-variant_dir-support 7 сар өмнө
binding_generator.py 823a08ad8e Don't reloading `print_error` interface function 3 өдөр өмнө
build_profile.py c4f1abe3f9 [Bindings] Build profile now strips methods and skip files 1 жил өмнө
doc_source_generator.py fe68c22c3e Generate GDExtension interface header and loader from JSON 1 сар өмнө
make_interface_header.py b895ed9f9c gdextension: Sync with upstream commit 481f36ed20520db3195a09cc309abf48c03cf51a (4.6-rc1) 2 долоо хоног өмнө
pyproject.toml 64cdf089d9 CI: Various version bumps; sync with main repo 9 сар өмнө

README.md

godot-cpp

[!NOTE]

For GDNative (Godot 3.x), switch to the 3.x or the 3.6 branch.

This repository contains the C++ bindings for the Godot Engine's GDExtensions API.

Versioning

[!WARNING]

The master branch of godot-cpp (version 10.x) is currently in Beta. You may prefer to choose a previous version to build on top of instead:

Starting with version 10.x, godot-cpp is versioned independently from Godot. The godot-cpp version you choose has no bearing on which Godot versions it is compatible with.

Until we have a stable release branch, you can use the master branch, or choose any of the previous version branches and tags for your project.

Compatibility

GDExtensions targeting an earlier version of Godot should work in later minor versions, but not vice-versa. For example, a GDExtension targeting Godot 4.3 should work just fine in Godot 4.4, but one targeting Godot 4.4 won't work in Godot 4.3.

You can specify which version you are targeting with the api_version option:

scons api_version=4.3

... or by providing a custom extension_api.json generated by the Godot version you are targeting:

godot --dump-extension-api
scons custom_api_file=extension_api.json

If you don't provide api_version or custom_api_file, then, by default, godot-cpp will target the latest stable Godot version that it's aware of.

Contributing

We greatly appreciate help in maintaining and extending this project. If you wish to help out, please visit the godot-cpp section of the Contributing docs.

Getting started

You need the same C++ pre-requisites installed that are required for the godot repository. Follow the official build instructions for your target platform.

Building your extension will create a shared library. To use this in your Godot project you'll need a .gdextension file, for example:

[configuration]

entry_symbol = "example_library_init"
compatibility_minimum = "4.1"

[libraries]

macos.debug = "res://bin/libgdexample.macos.debug.framework"
macos.release = "res://bin/libgdexample.macos.release.framework"
windows.debug.x86_64 = "res://bin/libgdexample.windows.debug.x86_64.dll"
windows.release.x86_64 = "res://bin/libgdexample.windows.release.x86_64.dll"
linux.debug.x86_64 = "res://bin/libgdexample.linux.debug.x86_64.so"
linux.release.x86_64 = "res://bin/libgdexample.linux.release.x86_64.so"
# Repeat for other architectures to support arm64, rv64, etc.

See the example.gdextension used in the template project for a complete example.

The entry_symbol is the name of the function that initializes your library, for example:

extern "C" {

// Initialization.

GDExtensionBool GDE_EXPORT example_library_init(GDExtensionInterfaceGetProcAddress p_get_proc_address, GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) {
	godot::GDExtensionBinding::InitObject init_obj(p_get_proc_address, p_library, r_initialization);

	init_obj.register_initializer(initialize_example_module);
	init_obj.register_terminator(uninitialize_example_module);
	init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE);

	return init_obj.init();
}
}

The initialize_example_module() should register the classes in ClassDB, similar to a Godot module:

using namespace godot;
void initialize_example_module(ModuleInitializationLevel p_level) {
	if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
		return;
	}
	GDREGISTER_CLASS(Example);
}

Any node and resource you register will be available in the corresponding Create... dialog. Any class will be available to scripting as well.

Examples and templates

See the godot-cpp-template project for a generic reusable template.

Or checkout the code for the Summator example as shown in the official documentation.