Post #114: Handling Quit Requests with Godot
Today I stumbled across another great piece of the Godot docs. This section of the docs explain how to handle "quit requests", which is when someone is closing your game. (For example, they press the red "x" button on the game window.)
Godot allows you to override the default behavior, so you can control what happens. For example, it may be useful to save some type of game state before the game closes so the player doesn't lose progress, or send a message to a server that the player has quit and it doesn't need to track the resources for that player anymore.
You can very easily override the default with:
get_tree().set_auto_accept_quit(false)
You can send your own quit notification to the nodes in the scene tree with:
get_tree().root.propagate_notification(NOTIFICATION_WM_CLOSE_REQUEST)