Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SceneTree.get_node_count_in_group() #78206

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/classes/SceneTree.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@
Returns the number of nodes in this [SceneTree].
</description>
</method>
<method name="get_node_count_in_group" qualifiers="const">
<return type="int" />
<param index="0" name="group" type="StringName" />
<description>
Returns the number of nodes assigned to the given group.
</description>
</method>
<method name="get_nodes_in_group">
<return type="Node[]" />
<param index="0" name="group" type="StringName" />
Expand Down
11 changes: 11 additions & 0 deletions scene/main/scene_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,16 @@ bool SceneTree::has_group(const StringName &p_identifier) const {
return group_map.has(p_identifier);
}

int SceneTree::get_node_count_in_group(const StringName &p_group) const {
_THREAD_SAFE_METHOD_
HashMap<StringName, Group>::ConstIterator E = group_map.find(p_group);
if (!E) {
return 0;
}

return E->value.nodes.size();
}

Node *SceneTree::get_first_node_in_group(const StringName &p_group) {
_THREAD_SAFE_METHOD_
HashMap<StringName, Group>::Iterator E = group_map.find(p_group);
Expand Down Expand Up @@ -1589,6 +1599,7 @@ void SceneTree::_bind_methods() {

ClassDB::bind_method(D_METHOD("get_nodes_in_group", "group"), &SceneTree::_get_nodes_in_group);
ClassDB::bind_method(D_METHOD("get_first_node_in_group", "group"), &SceneTree::get_first_node_in_group);
ClassDB::bind_method(D_METHOD("get_node_count_in_group", "group"), &SceneTree::get_node_count_in_group);

ClassDB::bind_method(D_METHOD("set_current_scene", "child_node"), &SceneTree::set_current_scene);
ClassDB::bind_method(D_METHOD("get_current_scene"), &SceneTree::get_current_scene);
Expand Down
1 change: 1 addition & 0 deletions scene/main/scene_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ class SceneTree : public MainLoop {
void get_nodes_in_group(const StringName &p_group, List<Node *> *p_list);
Node *get_first_node_in_group(const StringName &p_group);
bool has_group(const StringName &p_identifier) const;
int get_node_count_in_group(const StringName &p_group) const;

//void change_scene(const String& p_path);
//Node *get_loaded_scene();
Expand Down