+1 vote

I would like to get the resource path (ie "res://src/Node.tscn") from GDScript (ie var my_path = get_scene_path()). Is this possible?

in Engine by (670 points)

1 Answer

+1 vote
Best answer

It is possible to get the resource path of a script attached to a node. See this question.



self.get_script().get_path().get_base_dir() # if you just want the directory

This doesn't necessarily give you the path to the scene (i.e. if the scene is inherited or if the script is shared among multiple scenes). I do not know of a way to pick a node and ask it to tell you the scene that was loaded and caused it to be added to the tree.

by (629 points)
selected by
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.