diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp index 1069a752c4d2..02de3d4aaac0 100644 --- a/scene/gui/menu_button.cpp +++ b/scene/gui/menu_button.cpp @@ -138,7 +138,7 @@ void MenuButton::_notification(int p_what) { } break; case NOTIFICATION_INTERNAL_PROCESS: { - MenuButton *menu_btn_other = Object::cast_to(get_viewport()->gui_find_control(get_viewport()->get_mouse_position())); + MenuButton *menu_btn_other = Object::cast_to(get_viewport()->gui_get_hovered_control()); if (menu_btn_other && menu_btn_other != this && menu_btn_other->is_switch_on_hover() && !menu_btn_other->is_disabled() && (get_parent()->is_ancestor_of(menu_btn_other) || menu_btn_other->get_parent()->is_ancestor_of(popup))) { diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index dd3ae1ad3cbe..7d386191d832 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -1632,7 +1632,9 @@ void Viewport::_gui_call_notification(Control *p_control, int p_what) { Control *Viewport::gui_find_control(const Point2 &p_global) { ERR_MAIN_THREAD_GUARD_V(nullptr); - // Handle subwindows. + // `gui_find_control` doesn't take embedded windows into account. So the caller of this function + // needs to make sure, that there is no embedded window at the specified position. + _gui_sort_roots(); for (List::Element *E = gui.roots.back(); E; E = E->prev()) {