Handling quit requests

    On desktop platforms, the MainLoop has a special notification that is sent to all nodes when quitting is requested.

    On Android, MainLoop.NOTIFICATION_WM_GO_BACK_REQUEST is sent instead. Pressing the Back button will exit the application if Application > Config > Quit On Go Back is checked in the Project Settings (which is the default).

    Note

    Handling the notification is done as follows (on any node):

    GDScript   C#

    1. {
    2. }

    When developing mobile apps, quitting is not desired unless the user is on the main screen, so the behavior can be changed.

    GDScript   C#

      While forcing the application to close can be done by calling SceneTree.quit, doing so will not send the quit notification. This means the function described above won’t be called. Quitting by calling will not allow custom actions to complete (such as saving, confirming the quit, or debugging), even if you try to delay the line that forces the quit.

      Instead, you should send a quit request: