0 votes

I'm trying to make my game do something when a quit request has been received. So it runs a function and then the game closes after that is done. The problem is that it only works in either the editor or when the game is exported as a debug. If I were to export the game as a release, this wouldn't work.

Anyone have any ideas why??

in Engine by (31 points)

What does your code look like?

func _notification(what):
    if what == MainLoop.NOTIFICATION_WM_QUIT_REQUEST:
        my_function()
        get_tree().quit() # default behavior

I'm using this which is from the docs just with an added function before the quit is called

What's the target platform? I don't know much about that notification, but digging around, it sounds like it might have a few quirks between various platforms.

Related, have you tried adding this to _ready()?

get_tree().set_auto_accept_quit(false)

Yes, this is being done on the first scene that is loaded when the game starts. Exporting it for Windows currently.

1 Answer

0 votes

To run code when the project is exiting, you can define an _exit_tree() method in a singleton (which will be freed when the project quits):

func _exit_tree():
    print("Exiting...")
    # Don't quit here, as it will be done by Godot automatically.
by (11,901 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.