[SOLVED] Adding a Node from GDNative C++ and Nativescript 1.1 "p_child" always null

KorosKoros Posts: 12Member
edited January 21 in Programming

UPDATE
As was pointed out on Github the new way to declare this is Class::_new() so this becomes:

Label *nlabel = Label::_new(); 
get_parent()->add_child(nlabel);

For Nativescript 1.1/Godot 3.1 Beta1 I can't get the following to work, p_child always ends up null:

Label *nlabel = new Label();
get_parent())->add_child(nlabel, true );

The exact error msg in 1.1/godot beta 1 is:

ERROR: add_child: Parameter ' p_child ' is null.
   At: scene/main/node.cpp:1127

Saw in Label.hpp that this:

static void *operator new(size_t);
static void operator delete(void *);

was changed to:
static Label *_new();

Had this working in Nativescript 1.0/Godot 3.0:

Label *nlabel = new Label();
((Label *)owner->get_parent())->add_child(nlabel, true );
nlabel->set_text("This is a Label node added dynamically from GDNative C++");
nlabel->set_scale(Vector2(2,2));
nlabel->set_name("myLabelAddedFromC++");

Any help appreciated :smiley:

What is the correct way to declare and init a Label?
btw this is a script dropped on the sprite from the tutorial for GDNative
http://docs.godotengine.org/en/latest/tutorials/plugins/gdnative/gdnative-cpp-example.html

UPDATE
As was pointed out on Github the new way to declare this is:
Label *nlabel = Label::_new();
get_parent()->add_child(nlabel);

Answers

  • MegalomaniakMegalomaniak Posts: 1,087Admin
    Answer ✓

    Just a note, rather than editing the OP you could have written and submitted a reply, then reloaded the page to see the option to mark your own reply as the answer. ;)

  • KorosKoros Posts: 12Member

    @Megalomaniak said:
    Just a note, rather than editing the OP you could have written and submitted a reply, then reloaded the page to see the option to mark your own reply as the answer. ;)

    Will keep that in mind :smile:

Sign In or Register to comment.