GDNative vs. Godot engine module - what's the best for a C++ codebase

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By macemen

I’m in the process of porting my game written (partly) in C++ to Godot 3.1. Having read through most of the documentation on Godot Docs – 3.1 branch — Godot Engine (3.1) documentation in English I found that there are two ways on integrating a C++ codebase into a Godot game:

So far I have only got a very small “toy” feature working with GDNative but it looks quite promising. However after having recently learned about the native engine modules I started thinking whether that would be a better way forward.

I intend to use GDScript for the UI and as glue code and keep the core logic of the game in C++. It appears that both options would work for this purpose. What I like about GDNative is that I do not depend on a custom built engine and can keep all my code in a single repository. Can you guys list some pros and cons for each to help me make an informed decision? Thanks.

:bust_in_silhouette: Reply From: Zylann

GDNative works on desktop and mobile. Web isn’t supported but it’s being worked on. It is easier to share and update separately (so it’s nice for plugins). By its nature and state, GDNative is a bit more unsafe than modules, some issues were reported about crashes and memory leaks so if it works it doesn’t necessarily mean it works correctly. Watch out for these and report/fix if you can. Also, GDNative behaves like scripts, so the same limitations apply. Watch out for the version of Godot as well, your bindings must always be up to date, even for minor versions (they are said to be forward compatible but sometimes an ABI incompatibility can sneak through, while API remains compatible).

A module, on the other hand, is much simpler in terms of setup (no bindings, no C++to-C-to-C++ backend), and works everywhere as long as your C++ code doesn’t call into APIs not found on some platforms. It also allows you to define your own built-in classes and benefit from tighter access to the engine. Although, for a module you have to compile the entire engine together. The simplicity makes it a more stable option but it can be a burden to share or waiting for it to compile, and you have to use SCons.

In both cases you have to compile for all platforms you want to support, and you have to interface with the engine while it’s possible to make your logic part not depend too much on it.

I can’t give a personal preference because I’d be biased, I haven’t used GDNative for a very long time, only worked using modules. If GDNative works for you so far I’d say keep going, and if you have problems it may help improving the bindings.

Hi Zylann,
I want write a game using modules C++, but i don’t known how to load gui make from Godot editor, can you share demo build game with modules c++?

kenjivn | 2021-03-28 09:18