0 votes

I have found out how to get the path to the current script:

get_script().get_path()

I would like something similar to the above,. but for the path to the current scene.

in Engine by (33 points)

3 Answers

–1 vote

Alright so you can simply go to a scene like this

get_tree().change_scene("res:// LOCATION OF SCENE")

For example get_tree().change_scene("res://MainScenes/Enemy.tscn" ) will take me to Enemy Scene. Of course it was just an example.

by (411 points)
edited by

For future, this kind of "clarifying" question should be posted as a Comment, not an Answer.

0 votes

I have multiple scenes, when I press the "Back" button in the game, I want to be able to change scene to the last scene before the current scene.
So, before I do gettree().changescene() I want to store the path to the current scene in a global.array, so that in a future scene I can return to the last scene stored in the global.array.

by (33 points)

As above, this too should be a Comment, not an Answer. Otherwise, people looking at the forum overview page may ignore the question as it already appears to have been answered.

+4 votes

Nodes have a filename property. If a node is the root of a scene instance (like the current "scene" is), filename will contain the path to the scene file.
https://docs.godotengine.org/en/stable/classes/class_node.html#class-node-property-filename

by (27,831 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.