diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index d3668c5a6..c40f7fcab 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -1132,7 +1132,7 @@ void SceneTree::set_pause(bool p_enabled) { PhysicsServer::get_singleton()->set_active(!p_enabled); Physics2DServer::get_singleton()->set_active(!p_enabled); - + if (get_root()) { get_root()->propagate_notification(p_enabled ? Node::NOTIFICATION_PAUSED : Node::NOTIFICATION_UNPAUSED); } @@ -1360,6 +1360,23 @@ void SceneTree::get_nodes_in_group(const StringName &p_group, List *p_li p_list->push_back(ptr[i]); } } +Node *SceneTree::get_first_node_in_group(const StringName &p_group) { + _THREAD_SAFE_METHOD_ + + RBMap::Element *E = group_map.find(p_group); + if (!E) { + return NULL; + } + + _update_group_order(E->get()); //update order just in case + + int nc = E->get().nodes.size(); + if (nc == 0) { + return NULL; + } + + return E->get().nodes[0]; +} void SceneTree::_flush_delete_queue() { _THREAD_SAFE_METHOD_ @@ -2233,6 +2250,7 @@ void SceneTree::_bind_methods() { ClassDB::bind_method(D_METHOD("set_group", "group", "property", "value"), &SceneTree::set_group); 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("set_current_scene", "child_node"), &SceneTree::set_current_scene); ClassDB::bind_method(D_METHOD("get_current_scene"), &SceneTree::get_current_scene); diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h index 042dd41ec..4b25a7a72 100644 --- a/scene/main/scene_tree.h +++ b/scene/main/scene_tree.h @@ -400,6 +400,7 @@ public: void queue_delete(Object *p_object); void get_nodes_in_group(const StringName &p_group, List *p_list); + Node *get_first_node_in_group(const StringName &p_group); bool has_group(const StringName &p_identifier) const; void set_screen_stretch(StretchMode p_mode, StretchAspect p_aspect, const Size2 &p_minsize, real_t p_scale = 1.0);