The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

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):
        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()?


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():
    # Don't quit here, as it will be done by Godot automatically.
by (12,878 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 Frequently asked questions and 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 [email protected] with your username.