• General Chat
  • Why does Godot advertise C++ as a supported language?

I've been working with Godot for a few months now and I submitted a couple of games to the Godot Game Jam and LD35, both made in Godot in ~8 hours each.By now I'm somewhat used to GDScript, but when starting out I remember being pretty pissed that Godot advertised itself as supporting C++ when in fact it did not.Obviously curiosity made me investigate and I realized that IN THEORY, Godot supports C++. In practice it means giving up on a lot of Godot's features because they're only exposed to GDScript.Godot's support of C++ is basically limited to plug-ins.An analogy would be the Android NDK. It's official purpose is to offload critical performance code to C++ while still writing the rest of the app in Java. You can obviously code your way around that but you lose direct access to many useful features exposed only to Java.

That's how all engines offer c++ support. On source level and/or through plugin API's. You think unreal's any different?

Messed around with Unreal a bit back when I was still in highschool.IIRC the status of C++ as a first-class language in Unread changed in every version. Unreal 3 behaved mostly as you described.Nowadays, technically, Unreal 4 re-introduced C++ as a first-class language:[url=https://docs.unrealengine.com/latest/INT/Programming/Introduction/]https://docs.unrealengine.com/latest/INT/Programming/Introduction/[/url]CryEngine also supports C++ as a first-class language. They added C# support but only recently.Now that doesn't mean I'll drop Godot for Unreal or CryEngine .With or without C++ support they're way too posh for me in terms of additional costs. Especially since as a one man band I can't really aim for big games.It's just that at first I came out with the (wrong) impression that I could write most of the game in C++ and use GDScript as a scripting language.It turned out I had to write pretty much the whole game in GDScript.Learned the hard way GDScript is not fast enough to write complex math in yet so I had to move most of that code in a module.Unfortunately I don't have oodles of free time on my hands as I'd love to investigate making Godot access compiled C/C++ code as "scripts" from a shared library instead of GDScript bytecode.Code could be written like this:[code]#pragma onceGDCLASS()class Enemy : public Node2D{    OBJ_TYPE(Enemy, Node2D);    public:        void ready();        void process(float delta);}[/code][code]#include "Enemy.h"void Enemy:GDN_ready(){    //foo...}void Enemy:GDN_process(float delta){    //bar...}[/code]Ah, this is only a pipe dream though.Anyways, sorry for the bother.

I'm pretty sure you can do the code the way you showed. However, adding this to the game would require a custom glue indeed. The [tt]bin/tests[/tt] folder of the source have this as examples, since they're simple Godot games written completely in C++.A way to do this is to create custom nodes as C++ classes (one for player, another for enemy, etc.) and them glue those together using scenes in the editor. Technically you could even attach scripts to those in editor. I never tried this, but for what I know it should work.I don't understand what features of the API you can access through GDScript but not through C++.Anyway, the state of C++ is just that it has no documentation whatsoever. We discussed about it to make a doc page showing how to create a game with C++ (but there are so many things to do that this don't seem like will be done so soon).

That's a nice idea. Might try it out this weekend or the next time I have a couple of free hours of time.

a year later

UPDATE

This article outlines the introduction of GDNative (previously named "DLScript" -- renamed to avoid confusion because it's a middle-man /proxy to integrate coding languages rather than a new language itself).

This opens up the Script API calls of Godot to more languages than just GDScript by default (i.e. without needing to tweak and recompile the Godot source).

However, unlike adding custom modules to Godot, GDNative libraries and scripts will NOT have access to all C++ classes in the Godot engine, and cannot extend the base engine functionality (example for custom modules: if you want to extend or replace Godot's rendering engine -- neither GDScript nor GDNative scripts can do this)

(If you're interested in recompiling Godot to add C++ modules to extend Godot's engine see Akien's post here or the guide in the Godot Docs here).

The introduction of GDNative module allows attaching (previously unsupported) language libraries to nodes (after you've compiled them) -- essentially letting you attach compiled scripts from other languages +and also+ lets you code function libraries in other languages then call them from GDScript. Which I've read could be better for performance-critical scripts or heavy calculations.

There's a simple example in that link to move a KinematicBody2D using C++ code though GDNative.

GDNative is limited for now, and is a work in progress, but essentially delivers on that promise that you can script using C++ out-of-the-box.