GDExtension code works in editor, not in game.
Asked Answered
B

4

0

The code to wrap the hex tiles around the camera works in the editor, but doesn't work in game.
I'm think it has something to do with getting the NodePath of the cameraRig, because in the debugger, I'm getting this error:

E 0:00:00:0372   get_node_or_null: Can't use get_node() with absolute paths from outside the active scene tree.
  <C++ Error>    Condition "!data.inside_tree && p_path.is_absolute()" is true. Returning: nullptr
  <C++ Source>   scene/main/node.cpp:1550 @ get_node_or_null()

This is the code for setting and getting the cameraRig:

    void setCameraRig(NodePath p_nodePath) { cameraRig = Object::cast_to<Node3D>(get_node_internal(p_nodePath)); }
    NodePath getCameraRig() {
        if (cameraRig != nullptr) {
            return cameraRig->get_path();
        } else {
            return NodePath();
        }
    }
Burnejones answered 18/10, 2023 at 19:26 Comment(0)
S
0

Burnejones The error message is rather self-explanatory. Your code is calling one of get_node*() methods on a node that is not (yet) in the scene tree, passing it an absolute path argument. The error is thrown because absolute paths only make sense for nodes within the scene tree.

Sucrose answered 18/10, 2023 at 20:34 Comment(0)
B
0
if (cameraRig != nullptr && cameraRig->is_inside_tree()) { // This throws the same error
    return cameraRig->get_path();
} else {
    return NodePath(); // Could it be that it's considering this an absolute path?
}
Burnejones answered 18/10, 2023 at 22:49 Comment(0)
S
0

Burnejones Easy to test. Again, look at the Godot source. In node_path.h, you'll see there's a member function NodePath::is_absolute(). So you can check it. You can also do it before every get_node*() call. One of them must be throwing that exception.

Sucrose answered 18/10, 2023 at 23:9 Comment(0)
B
0

I have been looking at the source using the search tools in vscode. I don't have access to this function in godot-cpp:
rel_path_to()

    void setCameraRig(NodePath p_nodePath) { cameraRig = Object::cast_to<Node3D>(get_node_internal(p_nodePath)); cameraRigPath = p_nodePath; }
    NodePath getCameraRig() {
        if (cameraRig != nullptr && cameraRig->is_inside_tree()) {
            return cameraRigPath;
        } else {
            return NodePath();
        }
    }

If I save p_nodePath in a variable all its own, it returns this message:

E 0:00:00:0401   get_node: Node not found: "../CameraRig" (relative to "HexMap").
  <C++ Error>    Method/function failed. Returning: nullptr
  <C++ Source>   scene/main/node.cpp:1626 @ get_node()

So CameraRig doesn't exist at game runtime?

Burnejones answered 19/10, 2023 at 10:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.