Retrieve the folder path of the current scene

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

For my 3D game, I want the player to enter houses and when they leave, re-enter the scene from before. To load the scene from before, I want to set a global variable with the folder path of the current scene to load it back with the get_tree().change_scene_to_file('previous_scene') function.

Solved: I meant the scene_file_path property that I found now

:bust_in_silhouette: Reply From: GameSchool

Hi
Sounds like something an autoload will solve.
You can add a new script as an autoload in the project settings and store the scene path there as a variable.

Godot provides a tutorial for using autoload Singletons: Singletons (Autoload) — Godot Engine (stable) documentation in English

putper | 2023-06-02 08:24

Based on @AcoAlex’s (now hidden) comment, I wonder if you’re looking for something like:

get_tree().current_scene.scene_file_path

Docs here

jgodfrey | 2023-06-02 13:43

1 Like