0 votes

I wanted to play a very short animation when the player quits the game. I put the animation in a separate scene called Outro.tscn and tested it to make sure it works. Now I tried to play it on an Quit Request like this:

func _notification(what):   
    if what == MainLoop.NOTIFICATION_WM_QUIT_REQUEST:           
        print("Quitting requested...") 
        print("Playing Outro and Quit!")             
        get_tree().change_scene("res://Outro.tscn")

The functions gets called properly and both print lines are shown but the the Outro Scene is not played and there is no error shown either.

I would like to understand why that doesn't work and I'm looking for a way to make the animation play whenever the game is quit. Glad if anyone could help!

Godot version 3.5
in Engine by (15 points)

1 Answer

+1 vote
Best answer

I assume that your game is exiting when the NOTIFICATION_WM_QUIT_REQUEST is processed, right? If so, that's why the animation isn't playing.

You can effectively "ignore" the quit request using this code:

get_tree().set_auto_accept_quit(false)

With that done, the game won't exit and your animation should play. However, you'll then need to manually exit the game when the animation finishes playing.

To do that, you could wire up the animation_finished signal in the outro scene. In that callback, you can exit the game via:

get_tree().quit()

by (19,284 points)
selected by

Worked like a charm. Thank you!

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.