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++");
nlabel->set_scale(Vector2(2,2));
nlabel->set_name("myLabelAddedFromC++");

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

Any help appreciated! :)
Quote

asked Jan 19 in Engine by aurodev (19 points)

1 Answer

0 votes
Best answer

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);
answered Jan 21 by aurodev (19 points)
selected Jan 21 by aurodev
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 How to use this Q&A? before posting your first questions.