Help overwritting a resource that already exists when saving it

Save or overwrite a resource

Question

Hello, is there any way of overwriting/replacing a resource when calling ResourceSaver.save if the path is already used by another resource?
Cheers

That’s the default behaviour… Is it not working?

Hey, sorry for the late reply. No, it keeps the old data, not the saved one. Also I checked the Error returned by that call, and it’s 0, so looks like everything should have worked as expected. Must be worth mentioning that I’m using a tool script.

If you have an instanced Resource, that can have value overrides. Even if you change the base resource, the overrides take precedence. What are you doing exactly? Show your code, your node tree, your project. Don’t make people guess.

Im also having this issue and I have no idea why.ResourceSaver.save(new_waves_resource, "res://Areas/Area Grassy Plains/Level Data/" + file_name) This will only work If I manually delete the file so it can create a new one with the proper data, as even trying to delete the resource through code refuses to work as well.

1 Like

I’m pretty sure Godot treats resource files similar to instances of an object. All the data regarding that instance is stored in the corresponding file at the given resource path.

You can use the take_over_path() function to tell Godot to link any future loads to your new instance.

var resource = MyResource.new()
resource.take_over_path(path)

# You can now overwrite the file at path
ResourceSaver.save(resource, path)
2 Likes