This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hello! I am trying to utilize GDScript to tell the engine to find the directory location of an object's tscn file or res file.

This is what I thought might work when you place it in an autoload script as a function:

func path_fetch(idx):
    var fetcher =

It was a theory in thought that "idx"is the node or object you want to fetch the id off from (i.e. [Node:####]) using get_instance_id(), then after starting the EditorFileSystemDirectory as new I could use use get_file_path() command to get the directory path (ex. res://path/to/file.tscn)

I did get a print when using get file path, and it didn't come out right when the file I wanted is in a folder "res://", also I ended up with this error:

0:00:02:0130 - Index p_idx=1289 out of size (files.size()=0)
Time: 0:00:02:0130
C Error: Index p_idx=1289 out of size (files.size()=0)
C Source: editor\editor_file_system.cpp:87
C Function: EditorFileSystemDirectory::get_file

1289 is one of many instance ids for an object (####), and for some reason it says it's out of size.

I wouldn't be surprised that this is not the way to fetch the filepath of an object but unless there is a better way to do it I'm open for ideas.

in Engine by (208 points)

1 Answer

+5 votes
Best answer

For Nodes you can use filename property:

by (2,308 points)
selected by

Oh wow, I was not aware of this function. Definitely saves me a lot of trouble despite I put up too much effort. ":D

But that's just the joy of attempting to dig into the GODOT API and discover what is there to figure out what works. Thanks!

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 Frequently asked questions and 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 [email protected] with your username.