I'm trying to save the game's state when the application is quit in any way. I tried searching online but couldn't find a solution that totally worked. I want to detect when the game is closed normally, the quit button is pressed in the game, CTRL+C is used in a terminal with the headless server, and when the stop button is pressed in the godot editor.
This partially works but it doesn't detect stopping the game in the editor or using CTRL+C in a terminal with a headless server
https://docs.godotengine.org/en/stable/tutorials/inputs/handling_quit_requests.html
func _notification(what):
if what == NOTIFICATION_WM_CLOSE_REQUEST:
get_tree().quit() # default behavior
I also tried extending SceenTree and using _finalize() but it doesn't detect stopping in the editor and I can't seem to access autoload globals
https://docs.godotengine.org/en/4.5/classes/class_mainloop.html#class-mainloop-private-method-finalize