Godot Version
4.5
Question
Hello all,
The topic is a bit confusing, so I’ll try to explain.
Currently, I’m building my game entirely in C++ using GDExtension.
When I want to create a scene with a root node or hierarchy of nodes where each node (or some of the nodes) contains code, I create the nodes through code. For example:
#ifndef GLOBAL_MANAGER_H
#define GLOBAL_MANAGER_H
#include <godot_cpp/classes/node.hpp>
#include <godot_cpp/variant/utility_functions.hpp>
using namespace godot;
class GlobalManager final : public Node {
GDCLASS(GlobalManager, Node);
protected:
static void _bind_methods();
public:
void _ready() override {
UtilityFunctions::print("GlobalManager autoload initialized.");
}
void doSomething() {
UtilityFunctions::print("GlobalManager::doSomething called.");
}
};
#endif // GLOBAL_MANAGER_H
I’m not sure if this is the best approach, as I’m creating many new nodes in Godot which I add from the “Add Node” window.
Maybe a better approach is to create the scene tree, and for each node in the hierarchy, I will add a child node which will contain the C++ code. I don’t know…
What do you think is the best approach? Should I just create the nodes in code and add them, or is there a better way?