#Using an EditorScript to save Resources via ResourceSaver does not seem to function.

1 messages · Page 1 of 1 (latest)

coarse warren
#

Howdy there. I have a very data-heavy set of gameplay mechanics I'm importing from a CSV and then parsing using my own EditorScript. When I import them and unit tests all pass, I want to use ResourceSaver to save them to file.

The problem is that this does not appear to be working even though no errors are firing.

The path:

var bp_path : String = "res://resources/spell_creation/blueprints/"

The save logic that fires when unit tests pass:

I have the path and then I append the lowercase name of the data object to it. But though I get no errors, I don't notice my directories for my project being updated.

Other notes:

  • I have existing resources in these directories which share names with the ones that are automatically generated, and I don't know if they're overwritten by default, or if this is causing the save process to fail.
ashen meteor
#

I think save() might return an error code that you can look up

#

Probably file not found.. what does a sample path look like?

#

@coarse warren there is even a method to convert that error code to a string in globalscope

coarse warren
#

Yeah I see that the save() method returns a type, so I can use that to see if that works.

anyway, the sample path would be something like res://resources/spell_creation/blueprints/fireball (It was not clear in the docs if ResourceSaver adds the .tres automatically)

ashen meteor
#

Better print it out once to see if that path is right. Also try adding the tres, I don’t think it does that and it uses it to check which saver to use for a path. Like res or tres

coarse warren
#

Will try that; thanks!

coarse warren
#

Really quick since I anticipated this happening, but when I update any of the resource files that were saved, they don't appear to be getting overwritten and updated when I save them again via script. Is there something specific I need to do here?

ashen meteor
coarse warren
#

Inspector, after the files are saved

ashen meteor
#

I think you might have to deselect the resource and select it again. Or use a plugin script to refresh it perhaps

coarse warren
#

Tried deselecting, no luck. I guess in the worst case scenario, I can just delete the data and repopulate it. Existing scenes using those reference surprisingly don't null out their fields 😬

#

Thanks for the help!

#

For anyone else:
https://forum.godotengine.org/t/how-to-overwrite-a-custom-resource-file-in-tool-mode/9407

"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()
"

ashen meteor
#

thanks for helping anyone searching for this in the future gdthumbsup

coarse warren
#

I'm still parsing the solution and how to actually go about implementing it. Would I need to do this

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

After every instance of using ResourceSaver to save?

ashen meteor
#

once you're done with all of them is probably fine, since it doesn't need to refresh each one of them

#

or actually, it says update_file.. so it might be individual, yeah

#

but filesystem also has a method to rescan the entire thing

#

depends what is more convenient for you

coarse warren
#

Well, this is only run in the editor whenever I'm updating an external spreadsheet and need to update the relevant files in game, so one large rescan is probably fine. I've not gotten this deep into the weeds with file system stuff yet 😅

ashen meteor
#

yeah sounds fine

#

EditorInterface is now an editor singleton btw, so you don't even need to use a plugin script, you can just use EditorInterface.get_resource_filesystem()

coarse warren
#

I've got that docs page opened right now 😄 Seems like that's what I'll call at the end of the process?

ashen meteor
#

ye

var fs := EditorInterface.get_resource_filesystem()
fs.scan()
coarse warren
#

That method worked, but the resource data didn't update. Guess I'll try individually then

#

Aaaand that doesn't seem to be working either.

var fs := EditorInterface.get_resource_filesystem()

if ResourceSaver.save(blueprint, bp_path) == OK:
    print_rich("[color=#9cb4dd]Blueprint saved successfully.")
    fs.update_file(bp_path)
else:
    printerr("ERROR: Failed to save Blueprint. Aborting process.")
    break
#

Ok, it updates, but only after I restart the editor. gddeadinside

#

Not ideal, but we take those. Thanks again for all the help! Marking as solved.