0 votes

I've made a script, that saves custom resources. Everything works fine until I try to overwrite an already existing resource, to update it.

When overwriting, the resource file is properly saved and I can see the data is correct when I look at it in an external text editor. However, when inspecting the resource in Godot, the editor still has the old version of the resource loaded.

If I first manually delete the file (in the filesystem dock, not via script) and then save the resource it is correctly loaded.

Is there any way to avoid this hassle? How can I tell Godot to reload a resource?

My save script looks like this at the moment:

var res = create_resource() 
var filepath = path+"../"+res.name+".tres"
ResourceSaver.save(filepath, res)
res.take_over_path(filepath)
Godot version 3.3.2.stable
in Engine by (35 points)

1 Answer

+2 votes
Best answer

Answering my own question:

In tool mode, if you're overwriting a resource and expect it's data to refresh within the editor you need to use an EditorPlugin script to re-scan the filesystem or update the status of the file individually.

Individual update would happen in this manner

var filesystem = get_editor_interface().get_resource_filesystem()
filesystem.update_file(filepath)

and scanning all files like this:

get_editor_interface().get_resource_filesystem().scan()
by (35 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.