I'm working on a small platformer game to learn Godot, and I have a main scene which is just a menu with a "start" button. The levels go from 0 to 3, and a "level complete" screen pops up between them.
Everything works as expected until I try to return to the main menu, where the game immediately closes. There is no error message, so I set breakpoints and watched the scene tree, where MainMenu
successfully gets loaded under root
. The _ready
method runs normally, but then _on_tree_exiting
gets triggered without hitting the breakpoint I set in _process
. I'm using get_tree().change_scene_to_file("res://ui/main_menu.tscn")
to switch my scenes, and I've tried using the deferred version of it as well. Is there something I am doing to cause the scene to be immediately unloaded, or is there something else happening that I should be aware of?
MainMenu
is marked as my main scene and is the entrypoint to the game if that is important.
My first guess was that it was unhappy I loaded a scene which was previously unloaded when I left the menu the first time, but I'm visiting my "level complete" scene 3+ times with no issues so it seems Godot is fine reloading scenes as needed.