#How to save game when i close it

1 messages · Page 1 of 1 (latest)

spark tartan
#

so im simply just trying to have the game automatically save when the application is closed. like pressing the x button on the window. but i dont think the data is being saved

extends Control

func _on_tree_exited() -> void:
    print("FFFFFFFFF")
    SaveData.save()

this script is also linked to the root control node btw. any feedback appreciated

Godot Version: 4.4.1

tulip elm
#

Sample script:

extends Node2D

func _ready() -> void:
    get_tree().auto_accept_quit = false

func _notification(what: int) -> void:
    if what == NOTIFICATION_WM_CLOSE_REQUEST:
        print("Code that is being run right before exiting")
        get_tree().quit()
#

"auto accept quit" is a project setting, so you can toggle the behaviour there instead of doing it via code

#

but it doesn't really make a difference which way round you choose to do that

#

Also, if you don't quit the game "manually" with get_tree().quit(), it won't close at all

#

if you disable auto accept quit, that is