In my game, I currently have a scene which stores a pause menu. This scene is instanced as a child of another scene which holds the player.
In the pause menu, I have a button that closes the game, and when running the scene with the menu, the game quits perfectly, but when I press that button in another scene, for example, the player scene, the game doesn't close. In order to open this menu, the player must press the Escape key, and then the game will freeze, showing the menu in a corner. All the buttons work perfectly aside from the exit game one, that only works when playing the Pause Menu Scene itself. That means that I can't exit the game when I'm playing outside the menu's scene.
Here's a bit of the code I used in the menu:
func _on_ExitDesktop_pressed():
MainButtons.visible = false
DesktopCheck.visible = true
Checks.visible = true
func _on_YesDesktop_pressed():
get_tree().quit()
The YesDesktop
function corresponds to the button that the player must press to exit the game, but this only works inside the menu scene.
I've also noticed that this issue applies to other statements that start with get_tree()
, like get_tree().get_root().set_disable_input(true)
Any help would be appreciated