Using C++ with Godot for non-game application

Godot Version

Godot 4.2

Question

I have a pet project that I want to pursue which possibly involves a lot of computation and data parsing. I have gone through a bit of the Godot documentation and I found that you can also use godot-cpp. Here, I am assuming that using the C++ backend would be a lot faster than GDScript.
After going through the documentation, I still cant see how I can use godot for my project. Here’s a brief description of the project I want to do:

  1. Data coming in through Serial connection (USB interface)
  2. Custom C++ library to parse the data and output it as something useful
  3. GDExtension access this useful data then somehow update this into the application
    Note: I am using Godot on Linux

My main question is:

  1. How can I connect my custom C++ library with godot without having to recompile the whole godot? In this documentation here, it is mentioned that I’d have to add my custom library into the modules/ directory of the godot repository. Is there any way I can somehow link or bind an .so file with Godot C++?
  2. One thing that I still dont get is how frequenct would the custom c++ function be called? For instance, the serial data comes in every 3 ms (around 333 Hz), would Godot somehow constraint the update rate since the update might be called every X FPS (e.g. 60 FPS)? I am not sure what Godot update rate is.
  3. If I am using the C++ Godot extension, can I still use GDSCript?

I have not started any projects with Godot, so some of the questions I have above might be a bit too basic, so I hope someone can point me in the right direction, if I am wrong.

Reason why I want to use Godot: I want to avoid having to use C++ libraries such as Qt framework, Imgui etc. since this would mean I’d probably have to write a lot of things from scratch. Godot provides a really nice interface, and I can easily re-arrange buttons as I want it to be. Also, Godot’s UI ROCKS! I have seen a lot of nice non-game applications made by other people. Link is here if anyone is interested.

Sounds like you’ve accidentally crossed into on Godot modules land, which do require engine recompilation.

godot-cpp is a GDExtension, which does not require engine recompilation. Here’s the recommendend template repo for getting started with GDExtension, and the docs tutorial.


It sounds like it would be better to use a thread and queue usb data for the engine to read per frame. Nodes and what not only call _process once per frame.


yes! in fact it’s a great flow to use GDScript to call your C++ functions, or build on top of custom classes.

Thanks for the clarification. I think no 1 and 3 make sense. Thank you for pointing out that mistake!

As for 2, I’ve read a few examples on running the some computation on different threads, but lets just say, in the case of a really simple setup (single threaded application), where all of the computations are done inside the _process() function, how fast does it actually run?

Quoting from here

Idle processing allows you to run code that updates a node every frame, as often as possible.

The function _process() is not synchronized with physics. Its rate depends on hardware and game optimization. It also runs after the physics step in single-threaded games.

From the first quote, it says every frame, there’s not much of an indication how fast can a frame be, but according to the second quote, it seems that I can run it as fast as my hardware is capable of. So does this mean that it could potentially run at a very high frequency given a powerful computer (e.g. gaming spec PC)?

You could strip down a lot of the engine, the physics tick is by default 60 time per second. Turn off VSync of course, but I think targeting a minimum 333fps is going to immediately put you in a wild optimization corner, highly recommend a thread. As an example most every game will use a separate thread for audio, including Godot.

That make sense, thank you for your input! I’ll keep that in mind for my project.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.