How to switch back to the previous scene automatically?

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

Hello everyone,

For my project, I just want to switch to the earlier scene from the current scene. Much like a back button, but it should be automatic, like there is a cutscene, which when ends, the game should continue from getting back to previous scene.

For example, if the previous active scene was main menu, and then changed scene to cutscene, then on ending of the cutscene, it should go back to main menu; but if the the previous active scene was options, and then changed scene to cutscene, then on ending of the cutscene, it should go back to options.

How do I do that?

:bust_in_silhouette: Reply From: dancaer69

You can do it using a global variable. Create(if you haven’t already) a script and autoload it(you can do it from project settings). In this srcipt put a variable for the previous screen(e.g var prev_scene). Then when you change scene store the current scene in the variable by call Global.prev_scene = currentScene(if global is the name of the sript you created). Then use change_scene(Global.prev_scene).

Thank you that solved the problem, Sir!

devAS | 2021-06-08 04:25