Main menu stops working after export

Godot Version

4.5 windows

Question

I’m currently working on a game with a main menu. The menu contains 3 buttons, two of them change the scene to a game area and a settings menu respectively, and the other exits the game. They all work in the editor but not after export.

here’s the output of the log file after launching the game from console:

Godot Engine v4.5.stable.official.876b29033 - https://godotengine.org
WARNING: Unable to initialize Windows common controls. Native dialogs may not work properly.
at: DisplayServerWindows (platform/windows/display_server_windows.cpp:6940)
OpenGL API 3.3.0 NVIDIA 573.44 - Compatibility - Using Device: NVIDIA - NVIDIA T550 Laptop GPU
ERROR: Can’t load dependency: ‘res://scenes/main_menu.tscn’.
at: (core/io/resource_format_binary.cpp:459)
ERROR: Error when trying to parse Variant.
at: (core/io/resource_format_binary.cpp:503)
ERROR: Error when trying to parse Variant.
at: (core/io/resource_format_binary.cpp:490)
ERROR: Failed loading resource: res://.godot/exported/133200997/export-7416c78d345eded4b396246a6c8adbe0-settings.scn.
at: (core/io/resource_loader.cpp:343)
SCRIPT ERROR: Parse Error: Could not preload resource file “res://scenes/settings.tscn”.
at: GDScript::reload (res://scripts/main_menu.gd:7)
ERROR: Failed to load script “res://scripts/main_menu.gd” with error “Parse error”.
at: load (modules/gdscript/gdscript.cpp:3041)

this is what the code of my main menu scene looks like:

extends Control
@export var play_scene: PackedScene
#@export var settings_scene: PackedScene
#const play_area = "res://scenes/GameSystem.tscn"

var game_scene = preload("res://scenes/GameSystem.tscn").instantiate()
var settings_scene = preload("res://scenes/settings.tscn").instantiate()

func _on_play_button_pressed() -> void:
	#get_tree().change_scene_to_packed($SceneHandler.scene1)
	get_tree().root.add_child(game_scene)
	get_tree().current_scene = game_scene
	queue_free()

func _on_settings_button_pressed() -> void:
	get_tree().root.add_child(settings_scene)
	get_tree().current_scene = settings_scene
	queue_free()

func _on_exit_button_pressed() -> void:
	get_tree().quit()

Changing the root scene to settings makes every button work properly except for the “settings” button in the main menu, which changes the game to an empty scene.

I checked and there’s no pausing or case sensitivity shenanigans going on.

Have you changed the export settings in any way? These kinds of errors will appear if dependencies aren’t exported

I don’t think so, my export settings are set to “export all resources in the project”, and the first page looks like this:

update: I just tried to export for the web too (I opened the project in waterfox, firefox, and edge), and it gave me a networkerror attempting to fetch resource.

Ok it works now that I just manually made a completely separate main menu scene.

This is it’s code in case anyone has the same obscure problem like 12 years later and wants to copy my homework:

extends Node

const play_scene = "res://scenes/GameSystem.tscn"
const settings_scene = "res://scenes/settings.tscn"

func _on_play_button_pressed() -> void:
	get_tree().change_scene_to_file(play_scene)


func _on_settings_button_pressed() -> void:
	get_tree().change_scene_to_file(settings_scene)


func _on_exit_button_pressed() -> void:
	get_tree().quit()

The error was a cyclical reference, using preload causes the entire scene to be loaded into the script, so the main menu contained the settings and the settings contained the main menu, Godot fails to load this cycle. As you’ve done, prefer to use strings to load resources that aren’t needed as a preload, same with @exporting PackedScenes, it’s usually better to use @export_file("*.tscn") and load.

2 Likes