0 votes

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 the following 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++");

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

Any help appreciated! :)

in Engine by (19 points)

1 Answer

0 votes
Best answer

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

Label *nlabel = Label::_new(); 
by (19 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.