I am new to Godot and itโs been some time since I used C++ (JVM andy). How does one include/add a child node to a parent node using GDExtension? So far I have my parent node (RtsCamera) and children (camera_socket -> camera) being added to the editor; however, after every reload of the project new duplicate children are attached. What is the SOP for adding children to GDExtension node classes?
RtsCamera.h
public:
//Child Nodes
Node3D *camera_socket = nullptr;
Camera3D *camera = nullptr;
RtsCamera.cpp
void RtsCamera::_ready() {
if (!camera_socket) {
camera_socket = memnew(Node3D);
camera_socket->set_name("CameraSocket");
this->add_child(camera_socket);
camera_socket->set_owner(this->get_owner());
//camera_socket->set_owner(this);
} else {
UtilityFunctions::print("CameraSocket already exists: " + camera_socket ->get_path());
}
if (!camera) {
camera = memnew(Camera3D);
camera -> set_name("MainCamera");
camera_socket->add_child(camera);
camera->set_owner(camera_socket->get_owner());
camera->make_current();
//camera->set_owner(camera_socket);
} else {
UtilityFunctions::print("Camera already exists: " + camera ->get_path());
}
}
I was able to use _exit_tree and free the nodes using queue_free() however this would remove the nodes even if I saved the project. Any help would be greatly appreciated