Thanks for your answers
davek
Yes I did that inside the child init and also again after I added the child with add_child(). Just to be sure 🙂
DaveTheCoder
I used get_child_count() on my Parent Node and then run a for loop with:
Node *child = get_child(i); String child_name = child->get_name();
The names were correct and the Childs were there. Maybe there is a better way to print the whole tree?
After trying around for hours I maybe found the reason. Hopefully it helps someone saving some time in the future. These things were important:
The child Class also needs this GDCLASS(ChildNode, Node2D); in its class declarations. I thought that's just something the Parent class needs to be recognised by Godot. Then it also needs to have the static void _bind_methods().
When init the childClass you have to use ChildNode * childNode = memnew(ChildNode);
ChildNode * childNode = new ChildNode(); doesn't work. Also just having ChildNode childNode; in your parent class declarations and then using add_child(&childNode); doesn't work.
And now the biggest part: All your child Nodes need to be in you void initialize_gdmain(ModuleInitializationLevel p_level) or however you call it in your register_types.cpp. Something like that: ClassDB::register_class< ChildNode>();
Maybe I missed this part in the GDExtension tutorial 🙂 Anyway. If I can skip some parts or if someone knows why I have to use memnew() to make it work that would be interesting.
Greetings