From a36e393fb2adbcee1dbd5cdd68fc2b734fe1b9a7 Mon Sep 17 00:00:00 2001 From: Prakhar Shukla Date: Mon, 23 Nov 2026 15:03:21 +0530 Subject: [PATCH 1/2] Godot addon: Fix script editor menu in Godot 4.8 Signed-off-by: Prakhar Shukla --- addons/GDQuest_GDScript_formatter/menu.gd | 10 ++++++---- addons/GDQuest_GDScript_formatter_standalone/menu.gd | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/addons/GDQuest_GDScript_formatter/menu.gd b/addons/GDQuest_GDScript_formatter/menu.gd index 65f71fe..f98364c 100644 --- a/addons/GDQuest_GDScript_formatter/menu.gd +++ b/addons/GDQuest_GDScript_formatter/menu.gd @@ -75,14 +75,16 @@ func update_menu(show_uninstall: bool) -> void: ## Searches for and returns the last menu node in the script editor top menu bar, ## or null if not found. func _find_last_menu_button(script_editor: Control) -> MenuButton: - # The first child of the script editor should be a VBoxContainer (main container for the script editor main screen) - # Then the first child of that container should be an HBoxContainer (the menu bar) - # This is based on the current structure of Godot's script editor as of Godot 4.5 - # Note: We add multiple checks in there with null returns mainly in case something changes in a future if script_editor.get_child_count() == 0: return null var main_container := script_editor.get_child(0) + # Godot 4.8 wraps the existing layout in a DocumentEditorContainer. + if main_container.is_class("DocumentEditorContainer"): + if main_container.get_child_count() == 0: + return null + main_container = main_container.get_child(0) + if not is_instance_valid(main_container) or not main_container is VBoxContainer: return null diff --git a/addons/GDQuest_GDScript_formatter_standalone/menu.gd b/addons/GDQuest_GDScript_formatter_standalone/menu.gd index a0847dd..d8036b3 100644 --- a/addons/GDQuest_GDScript_formatter_standalone/menu.gd +++ b/addons/GDQuest_GDScript_formatter_standalone/menu.gd @@ -61,14 +61,16 @@ func update_menu() -> void: ## Searches for and returns the last menu node in the script editor top menu bar, ## or null if not found. func _find_last_menu_button(script_editor: Control) -> MenuButton: - # The first child of the script editor should be a VBoxContainer (main container for the script editor main screen) - # Then the first child of that container should be an HBoxContainer (the menu bar) - # This is based on the current structure of Godot's script editor as of Godot 4.5 - # Note: We add multiple checks in there with null returns mainly in case something changes in a future if script_editor.get_child_count() == 0: return null var main_container := script_editor.get_child(0) + # Godot 4.8 wraps the existing layout in a DocumentEditorContainer. + if main_container.is_class("DocumentEditorContainer"): + if main_container.get_child_count() == 0: + return null + main_container = main_container.get_child(0) + if not is_instance_valid(main_container) or not main_container is VBoxContainer: return null From a4357f6d27ccd3adf4aa57ceb315b825ec88dd78 Mon Sep 17 00:00:00 2001 From: Nathan Lovato <12694995+NathanLovato@users.noreply.github.com> Date: Thu, 26 Nov 2026 20:39:50 +0100 Subject: [PATCH 2/2] Refactor code to get the last menu button --- addons/GDQuest_GDScript_formatter/menu.gd | 31 ++++++++++--------- .../menu.gd | 31 ++++++++++--------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/addons/GDQuest_GDScript_formatter/menu.gd b/addons/GDQuest_GDScript_formatter/menu.gd index f98364c..a71ff4f 100644 --- a/addons/GDQuest_GDScript_formatter/menu.gd +++ b/addons/GDQuest_GDScript_formatter/menu.gd @@ -78,28 +78,29 @@ func _find_last_menu_button(script_editor: Control) -> MenuButton: if script_editor.get_child_count() == 0: return null - var main_container := script_editor.get_child(0) - # Godot 4.8 wraps the existing layout in a DocumentEditorContainer. - if main_container.is_class("DocumentEditorContainer"): - if main_container.get_child_count() == 0: - return null - main_container = main_container.get_child(0) - - if not is_instance_valid(main_container) or not main_container is VBoxContainer: + var version := Engine.get_version_info() + var main_container: Control = null + # In 4.8 onward, the script editor looks like this: + # ScriptEditor -> DocumentEditorContainer -> VBoxContainer -> HBoxContainer (menu bar) + if version.major == 4 and version.minor >= 8: + main_container = script_editor.get_child(0).get_child(0) + else: + main_container = script_editor.get_child(0) + + if main_container == null or not main_container is VBoxContainer: + printerr("GDScript formatter: main_container is null or not a VBoxContainer") return null - if main_container.get_child_count() == 0: - return null - - var menu_bar := main_container.get_child(0) - if not is_instance_valid(menu_bar) or not menu_bar is HBoxContainer: + var menu_bar := main_container.get_child(0) as HBoxContainer + if menu_bar == null: + printerr("GDScript formatter: menu_bar not found") return null # We reached the menu bar. So now we loop through all the children look for # the last menu button, which would be the last menu in the menu list. # Note: Here the goal is to insert the menu after the debug menu, but we - # don't check for the button text because "debug" would only work in English - # this should work in any language. + # don't check for the button text because "debug" would only work in English. + # This should work in any language. var last_menu_button: MenuButton = null for child in menu_bar.get_children(): if child is MenuButton: diff --git a/addons/GDQuest_GDScript_formatter_standalone/menu.gd b/addons/GDQuest_GDScript_formatter_standalone/menu.gd index d8036b3..6f5a1bb 100644 --- a/addons/GDQuest_GDScript_formatter_standalone/menu.gd +++ b/addons/GDQuest_GDScript_formatter_standalone/menu.gd @@ -64,28 +64,29 @@ func _find_last_menu_button(script_editor: Control) -> MenuButton: if script_editor.get_child_count() == 0: return null - var main_container := script_editor.get_child(0) - # Godot 4.8 wraps the existing layout in a DocumentEditorContainer. - if main_container.is_class("DocumentEditorContainer"): - if main_container.get_child_count() == 0: - return null - main_container = main_container.get_child(0) - - if not is_instance_valid(main_container) or not main_container is VBoxContainer: + var version := Engine.get_version_info() + var main_container: Control = null + # In 4.8 onward, the script editor looks like this: + # ScriptEditor -> DocumentEditorContainer -> VBoxContainer -> HBoxContainer (menu bar) + if version.major == 4 and version.minor >= 8: + main_container = script_editor.get_child(0).get_child(0) + else: + main_container = script_editor.get_child(0) + + if main_container == null or not main_container is VBoxContainer: + printerr("GDScript formatter: main_container is null or not a VBoxContainer") return null - if main_container.get_child_count() == 0: - return null - - var menu_bar := main_container.get_child(0) - if not is_instance_valid(menu_bar) or not menu_bar is HBoxContainer: + var menu_bar := main_container.get_child(0) as HBoxContainer + if menu_bar == null: + printerr("GDScript formatter: menu_bar not found") return null # We reached the menu bar. So now we loop through all the children look for # the last menu button, which would be the last menu in the menu list. # Note: Here the goal is to insert the menu after the debug menu, but we - # don't check for the button text because "debug" would only work in English - # this should work in any language. + # don't check for the button text because "debug" would only work in English. + # This should work in any language. var last_menu_button: MenuButton = null for child in menu_bar.get_children(): if child is MenuButton: