In C++, getting a node works the same way as in GDScript. The main difference is, because you work at engine-level, types and potential errors have to be checked:
Node * node = get_node(NodePath("Hello"));
// If the node can be found
if(node != NULL) {
Sprite * sprite = node->cast_to<Sprite>();
// If the node is a Sprite
if(sprite != NULL) {
// Do stuff with sprite
}
}
If you don’t check for NULLs and failed casts, you are likely to get crashes, so better avoid them if you know that can be broken by a wrong use of the editor/game data
I needed to add the c++ class explicitly as a child in the script, for example:
get_node("Node2D").add_child(c++_class_instance)
,
then use absolute paths in the c++ class , for example: