Is there a signal or something that a scene is unloaded?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jackash

Let me clarify. I want some script to run when the scene is to be destroyed, no matter why, whether game is closed or it’s just meant to change to another scene. For example on Android you have Activity::onDestroy()function which is executed when the activity is finished or being destroyed by a system, is there anything like that in Godot?

:bust_in_silhouette: Reply From: Dlean Jeans

You can override _exit_tree:

Called when the node is about to leave the SceneTree (e.g. upon freeing, scene changing, or after calling remove_child in a script). If the node has children, its _exit_tree callback will be called last, after all its children have left the tree.

Corresponds to the NOTIFICATION_EXIT_TREE notification in Object._notification and signal tree_exiting. To get notified when the node has already left the active tree, connect to the tree_exited


func _enter_tree():
    print("I'm out!")

you mean?

    print("I'm out")```
[wrap=footnote]Ha-kuro | 2022-08-24 04:44[/wrap]