How to write an effective "return" button?

Godot Version



The method I’ve used so far is to manually restore the previous scene.


func _on_back_from_settings_pressed():

But this code only allows you to return to the main menu from the settings. But logically, if I want to use it in-game, it will load the main menu as soon as I press the “return” button.

Since you’re changing the entire scene, you’ll need to use a static var to hold the previous scene path and point the change to that instead.

I thought about this but couldn’t find the necessary signal to restore. There are only “load scene from file” and “load scene from packed” signals.

There’s not. Once you change scenes, the previous one is destroyed, along with all the state. If you want to persist data after scene destruction you’re gonna have to do some extra work.