Merge pull request #25467 from fire/folding_spam

Add check in folding to see if the nodepath exists to avoid message spam and expose get_node_or_null
This commit is contained in:
Rémi Verschelde 2019-02-08 10:13:36 +01:00 committed by GitHub
commit 4ddefe9142
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 7 deletions

View file

@ -173,7 +173,7 @@ void EditorFolding::load_scene_folding(Node *p_scene, const String &p_path) {
for (int i = 0; i < unfolds.size(); i += 2) {
NodePath path = unfolds[i];
PoolVector<String> un = unfolds[i + 1];
Node *node = p_scene->get_node(path);
Node *node = p_scene->get_node_or_null(path);
if (!node) {
continue;
}

View file

@ -1311,7 +1311,7 @@ Node *Node::_get_child_by_name(const StringName &p_name) const {
return NULL;
}
Node *Node::_get_node(const NodePath &p_path) const {
Node *Node::get_node_or_null(const NodePath &p_path) const {
if (!data.inside_tree && p_path.is_absolute()) {
ERR_EXPLAIN("Can't use get_node() with absolute paths from outside the active scene tree.");
@ -1376,7 +1376,7 @@ Node *Node::_get_node(const NodePath &p_path) const {
Node *Node::get_node(const NodePath &p_path) const {
Node *node = _get_node(p_path);
Node *node = get_node_or_null(p_path);
if (!node) {
ERR_EXPLAIN("Node not found: " + p_path);
ERR_FAIL_COND_V(!node, NULL);
@ -1386,7 +1386,7 @@ Node *Node::get_node(const NodePath &p_path) const {
bool Node::has_node(const NodePath &p_path) const {
return _get_node(p_path) != NULL;
return get_node_or_null(p_path) != NULL;
}
Node *Node::find_node(const String &p_mask, bool p_recursive, bool p_owned) const {
@ -2709,6 +2709,7 @@ void Node::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_child", "idx"), &Node::get_child);
ClassDB::bind_method(D_METHOD("has_node", "path"), &Node::has_node);
ClassDB::bind_method(D_METHOD("get_node", "path"), &Node::get_node);
ClassDB::bind_method(D_METHOD("get_node_or_null", "path"), &Node::get_node_or_null);
ClassDB::bind_method(D_METHOD("get_parent"), &Node::get_parent);
ClassDB::bind_method(D_METHOD("find_node", "mask", "recursive", "owned"), &Node::find_node, DEFVAL(true), DEFVAL(true));
ClassDB::bind_method(D_METHOD("find_parent", "mask"), &Node::find_parent);

View file

@ -153,7 +153,6 @@ private:
void _print_tree_pretty(const String prefix, const bool last);
void _print_tree(const Node *p_node);
Node *_get_node(const NodePath &p_path) const;
Node *_get_child_by_name(const StringName &p_name) const;
void _replace_connections_target(Node *p_new_target);
@ -252,6 +251,7 @@ public:
Node *get_child(int p_index) const;
bool has_node(const NodePath &p_path) const;
Node *get_node(const NodePath &p_path) const;
Node *get_node_or_null(const NodePath &p_path) const;
Node *find_node(const String &p_mask, bool p_recursive = true, bool p_owned = true) const;
bool has_node_and_resource(const NodePath &p_path) const;
Node *get_node_and_resource(const NodePath &p_path, RES &r_res, Vector<StringName> &r_leftover_subpath, bool p_last_is_property = true) const;

View file

@ -55,7 +55,7 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
Node *p_name; \
if (p_id & FLAG_ID_IS_PATH) { \
NodePath np = node_paths[p_id & FLAG_MASK]; \
p_name = ret_nodes[0]->_get_node(np); \
p_name = ret_nodes[0]->get_node_or_null(np); \
} else { \
ERR_FAIL_INDEX_V(p_id &FLAG_MASK, nc, NULL); \
p_name = ret_nodes[p_id & FLAG_MASK]; \
@ -342,7 +342,7 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
}
for (int i = 0; i < editable_instances.size(); i++) {
Node *ei = ret_nodes[0]->_get_node(editable_instances[i]);
Node *ei = ret_nodes[0]->get_node_or_null(editable_instances[i]);
if (ei) {
ret_nodes[0]->set_editable_instance(ei, true);
}