GDNative, how do you create an instance in C++?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By KramchayDig

I want to know how to create an instance with GDNative C++ I got no idea how to do it.

An instance of what? A node instance? A scene instance? Do you know how to do it in GDScript to begin with? (I would recommend doing so before rushing C++ and GDNative)

Zylann | 2020-05-07 12:51

yes I want to create a node instance and add it in as a child from a parent.

KramchayDig | 2020-05-08 05:40

:bust_in_silhouette: Reply From: Zylann

In GDScript:

# Creates a Sprite node and adds it as child of the node
# the current script is attached on
var node = Sprite.new()
add_child(node)

In C++:

// I believe `new Sprite()` would not work, for reasons I don't remember
Sprite *node = Sprite::_new();
add_child(node);