Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_path() in Resource returns a empty string when it is created on disk. #92139

Open
leandro-benedet-garcia opened this issue May 20, 2024 · 2 comments

Comments

@leandro-benedet-garcia
Copy link

Tested versions

v4.2.1.stable.gentoo [b09f793]

System information

Godot v4.2.1.stable (b09f793) - Gentoo 2.14 - Wayland - GLES3 (Compatibility) - NVIDIA GeForce GTX 965M (nvidia; 550.67) - Intel(R) Core(TM) i5-6300HQ CPU @ 2.30GHz (4 Threads)

Issue description

I have this resource file:

@tool
extends Resource
class_name TestResource

@export var library_owner: string = default_var()

func default_var():
    print(get_path())

Instead of printing the path the resource was created, it will be blank instead.

I was hoping it to not be blank so I could develop a reusable plugin that executed something on the folder where the resource was created.

Steps to reproduce

Save the above resource, then create a new file using said resource.

Minimal reproduction project (MRP)

n/a

@leandro-benedet-garcia leandro-benedet-garcia changed the title get_path() returns a empty string when resource is created on disk. get_path() in Resource returns a empty string when resource is created on disk. May 20, 2024
@leandro-benedet-garcia leandro-benedet-garcia changed the title get_path() in Resource returns a empty string when resource is created on disk. get_path() in Resource returns a empty string when it is is created on disk. May 20, 2024
@leandro-benedet-garcia leandro-benedet-garcia changed the title get_path() in Resource returns a empty string when it is is created on disk. get_path() in Resource returns a empty string when it is created on disk. May 20, 2024
@tracefree
Copy link

Hi! It looks like this happens because the resource is initialized before you even get to choose the path in the file picker dialog. Resources don't seem to have a notification for when they are saved to disk, but the following hacky workaround using EditorFileSystem works:

@tool
extends Resource
class_name TestResource

@export var library_owner: String = await default_var()


func default_var() -> String:
	await EditorInterface.get_resource_filesystem().filesystem_changed
	print(get_path())
	return get_path()

@leandro-benedet-garcia
Copy link
Author

I thought that would be the issue, but what I would expect is an error to occur to tell me it could not be done, to exist a signal that is executed when a resource is created or at least a note in the documentation saying it was a expected behavior.

None of those things seem to be the case so I would say it is indeed a bug.

Ideally we would have the signal tho. That would be quite handy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants