0 votes

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 https://docs.godotengine.org/en/3.1/ I found that there are two ways on integrating a C++ codebase into a Godot game:
* GDNative C++ bindings
* Godot engine modules

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.

asked Dec 17, 2019 in Engine by macemen (15 points)

1 Answer

+1 vote
Best answer

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.

answered Dec 17, 2019 by Zylann (26,809 points)
selected Dec 17, 2019 by macemen
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.