How Godot's GDExtension system and the godot-cpp bindings work, and how to use Conan to bring C and C++ libraries into a Godot game, with a flecs example that simulates 100,000 particles.

166 points•czoido•2 days ago•66 comments•

66 comments

voodooEntity1 day ago
Was playing arround recently building an RTS with godot until i just hit the ceilling of what i could handle with gdscript performance wise.

Than started to move alot of heavy logic to c++ simulation : tedious indeed but the results speak for themself.

Basically allows me to use godot for things like menus dialogues and similar stuff while running the true heavy work in a c++ simulation.

8-prime1 day ago
What motivated you to use c++ rather than C#? Especially when you mention the usage of c++ being tedious, when I would argue using C# is equally straight forward as gdscript is.
voodooEntity1 day ago
A combination of two factors that are rather specific to myself. One being that even tho its quite some time ago i have a bit of c++ experience, while i never tried to code C#. So when i got the idea to try to run the heavy simulation in an "extension" it was just a language i was a bit familiar with. Maybe C# would have been the "smarter" choice, i just never digged into it yet.

The other reason is that in my well closer circle i got quite some people that code c++ on a daily basis and i don't know (at least i think so) anyone doin C# actively, so i thought if i would get stuck i have people i can easily ask about my c++ problems.

So it wasn't a "i think c++ is better than c#" decision rather a what do i know and what resources i have available easily.

windsurfer1 day ago
C# is a "first class" language in Godot and doesn't need a GDExtension, but it's not compatible with web builds yet. There is a draft PR that includes C# support but it adds about +50 MB to a web export and is also missing a few features.
pier251 day ago
Not sure how relevant this is for this simulation use case but IIRC C# has a bigger overhead when communicating with the core engine compared to GDScript or C++.
moffkalastabout 14 hours ago
At which point do you just switch to a cpp UI library and forget about the engine?
voodooEntityabout 14 hours ago
It's not like i didn't consider that step :D but as mentioned in another response the game contains some rather complex configurator etc systems that i already completely baked with the godot system, also a simple map editor that works fine - so im not to motivated to also rewrite them all. Apart from that its a hobby project (one of many) so well maybe i reach that point and go full c++ but for now i dont think i will.
momocowcow1 day ago
gdscript is incredibly slow, worst than something like lua, maybe only good for handling the UI events

the hierarchy and physics api isn’t great either, it’s easy to hit heap allocs even from a gdextension

a lot of things wrong with this generic engine, but at least it’s lightweight

Fraterkes1 day ago
Lots of things right too, thankfully
tancop1 day ago
Godot is only the best open source engine because Bevy is not ready for production, Lumberyard/O3DE is hard to set up and everything else is ancient or 2D only. one eyed man among the blind type shit
droptablemain1 day ago
Assuming it's a 2D game, why not just use something like SFML to build your own simple RTS engine at that point?

Seems like carrying a lot of Godot baggage around for nothing.

omoikane1 day ago
Godot comes with a lot of tools in addition to the runtime. Maybe they are using the IDE to do layouts for the menu dialogues, for example.

Also, I am not sure about how easy it is to build binaries using SFML for various platforms (such as WASM), but with Godot you just have to download the right template.

valorzard2 days ago
If you know rust, the Godot rust bindings for GDExtension are also really good and let you use any Rust library in Godot (including tokio and async rust if you really want) https://godot-rust.github.io/
aquariusDue1 day ago
Came here to mention this. As an example there's godot-iroh which uses iroh for peer to peer networking:

https://github.com/tipragot/godot-iroh

I'm a big fan of the godot rust bindings as well
fwsgonzo2 days ago
Just don't forget the versioning script needed on at least Linux. It's either that or build with the same older distro Godot uses, so you have a matching libstdc++ version. You can link with a newer stdlibc++ but you will need a linker versioning script that hides your impl from the dynamic linker so you don't get random ghosts in your machine.
czoido2 days ago
Hi! Yes, you are right, thanks for pointing this out. It's something to keep in mind when distributing an extension for Linux. I have just updated the post with a note about it.
MeteorMarc1 day ago
So, what profiling support is available to find the critical parts of your GDscript or C# code. Before needlessly jumping into c++ hassle for performance reasons? Tfa addresses functional reasons, which is ok.
Fraterkes1 day ago
For C# there’s basically nothing in engine, so you’d use Rider or Superluminal. Which is fine, Godot can have a bit too much nih imo
pjmlp1 day ago
I don't follow it that much, but I think there are no plans to improve GDscript performance other than maybe the interpreter itself, nothing with JIT or AOT in mind.

Also .NET integration has the issue it doesn't work in all target platforms, that is why Capcom and Unity have their own compilers to native code. Even when Unity finally adopts modern .NET, Native AOT naturally doesn't cover game consoles.

Rohansi1 day ago
It's too bad .NET AOT wouldn't support consoles. They use x86 and ARM processors that it already supports.
irskep1 day ago
Coming from Instruments (Apple) and Chrome Dev Tools, I found the Godot profiler to be hilariously hard to get useful results out of because of its simplistic presentation of information that you can't drill down into.
srikz1 day ago
Is Godot (or something else,say, Bevy) the right tool for building a complex, data intensive GUI app (like a DAW)?

I tried dear imgui for this before but I felt it was very low level and had to build a lot of systems (not it's intended use as a GUI app framework, tbf)

krapp1 day ago
Maybe?

I think it depends on what GUI tools it provides. Game engines aren't designed to be general purpose application frameworks either.

It's probably doable in Godot but you'll probably be building a lot of systems there as well, and probably writing a lot of plugins.

But people do it. I've seen plenty of applications in Unity.

Read the full thread on Hacker News →

Related stories