| Attention | Topic was automatically imported from the old Question2Answer platform. | |
| Asked By | jarlowrey |
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?
| Attention | Topic was automatically imported from the old Question2Answer platform. | |
| Asked By | jarlowrey |
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?
| Reply From: | markopolo |
It is possible to get the resource path of a script attached to a node. See this question.
self.get_script().get_path()
or
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.
| Reply From: | Ninfur |
In Godot 3.x:
node.filename
In Godot 4.0:
node.scene_file_path
thank you