diff options
Diffstat (limited to 'scene/main/node.cpp')
-rwxr-xr-x | scene/main/node.cpp | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp index c850a5ae74..adc52c501a 100755 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -194,7 +194,7 @@ void Node::_propagate_enter_tree() { data.depth = 1; } - data.viewport = cast_to<Viewport>(); + data.viewport = Object::cast_to<Viewport>(this); if (!data.viewport) data.viewport = data.parent->data.viewport; @@ -1353,20 +1353,24 @@ void Node::_add_child_nocheck(Node *p_child, const StringName &p_name) { void Node::add_child(Node *p_child, bool p_legible_unique_name) { ERR_FAIL_NULL(p_child); - /* Fail if node has a parent */ + if (p_child == this) { - ERR_EXPLAIN("Can't add child " + p_child->get_name() + " to itself.") + ERR_EXPLAIN("Can't add child '" + p_child->get_name() + "' to itself.") ERR_FAIL_COND(p_child == this); // adding to itself! } - ERR_EXPLAIN("Can't add child, already has a parent"); - ERR_FAIL_COND(p_child->data.parent); + + /* Fail if node has a parent */ + if (p_child->data.parent) { + ERR_EXPLAIN("Can't add child '" + p_child->get_name() + "' to '" + get_name() + "', already has a parent '" + p_child->data.parent->get_name() + "'."); + ERR_FAIL_COND(p_child->data.parent); + } if (data.blocked > 0) { - ERR_EXPLAIN("Parent node is busy setting up children, add_node() failed. Consider using call_deferred(\"add_child\",child) instead."); + ERR_EXPLAIN("Parent node is busy setting up children, add_node() failed. Consider using call_deferred(\"add_child\", child) instead."); ERR_FAIL_COND(data.blocked > 0); } - ERR_EXPLAIN("Can't add child while a notification is happening"); + ERR_EXPLAIN("Can't add child while a notification is happening."); ERR_FAIL_COND(data.blocked > 0); /* Validate name */ @@ -1381,7 +1385,7 @@ void Node::add_child_below_node(Node *p_node, Node *p_child, bool p_legible_uniq if (is_a_parent_of(p_node)) { move_child(p_child, p_node->get_position_in_parent() + 1); } else { - WARN_PRINTS("Cannot move under node " + p_node->get_name() + " as " + p_child->get_name() + " does not share a parent") + WARN_PRINTS("Cannot move under node " + p_node->get_name() + " as " + p_child->get_name() + " does not share a parent.") } } @@ -2160,9 +2164,9 @@ Node *Node::_duplicate(int p_flags) const { bool instanced = false; - if (cast_to<InstancePlaceholder>()) { + if (Object::cast_to<InstancePlaceholder>(this)) { - const InstancePlaceholder *ip = cast_to<const InstancePlaceholder>(); + const InstancePlaceholder *ip = Object::cast_to<const InstancePlaceholder>(this); InstancePlaceholder *nip = memnew(InstancePlaceholder); nip->set_instance_path(ip->get_instance_path()); node = nip; @@ -2180,7 +2184,7 @@ Node *Node::_duplicate(int p_flags) const { Object *obj = ClassDB::instance(get_class()); ERR_FAIL_COND_V(!obj, NULL); - node = obj->cast_to<Node>(); + node = Object::cast_to<Node>(obj); if (!node) memdelete(obj); ERR_FAIL_COND_V(!node, NULL); @@ -2270,7 +2274,7 @@ void Node::_duplicate_and_reown(Node *p_new_parent, const Map<Node *, Node *> &p print_line("could not duplicate: " + String(get_class())); } ERR_FAIL_COND(!obj); - node = obj->cast_to<Node>(); + node = Object::cast_to<Node>(obj); if (!node) memdelete(obj); } @@ -2326,7 +2330,7 @@ void Node::_duplicate_signals(const Node *p_original, Node *p_copy) const { NodePath p = p_original->get_path_to(this); Node *copy = p_copy->get_node(p); - Node *target = E->get().target->cast_to<Node>(); + Node *target = Object::cast_to<Node>(E->get().target); if (!target) { continue; } @@ -2355,7 +2359,7 @@ Node *Node::duplicate_and_reown(const Map<Node *, Node *> &p_reown_map) const { print_line("could not duplicate: " + String(get_class())); } ERR_FAIL_COND_V(!obj, NULL); - node = obj->cast_to<Node>(); + node = Object::cast_to<Node>(obj); if (!node) memdelete(obj); ERR_FAIL_COND_V(!node, NULL); @@ -2610,7 +2614,7 @@ void Node::_set_tree(SceneTree *p_tree) { static void _Node_debug_sn(Object *p_obj) { - Node *n = p_obj->cast_to<Node>(); + Node *n = Object::cast_to<Node>(p_obj); if (!n) return; |