diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index b46ce753ed1..3e73d589f89 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -2540,12 +2540,8 @@ int Tree::_count_selected_items(TreeItem *p_from) const { } } - if (p_from->get_first_child()) { - count += _count_selected_items(p_from->get_first_child()); - } - - if (p_from->get_next()) { - count += _count_selected_items(p_from->get_next()); + for (TreeItem *c = p_from->get_first_child(); c; c = c->get_next()) { + count += _count_selected_items(c); } return count;