I don't know how to solve this structural issue I'm having!
I want to give a user the possibility to select and use, at runtime, a font selected in his file system.
I want to copy the .ttf font file itself inside the "user://" folder and then loading it as a resource (as a font data) at every startup.
I save the font, I load it as a Resource and everything works fine.
My problem is when I already have the font saved in the "user://" folder but now I'm selecting a new font that will override the old one.
A file.remove() gives Error 1 (generic), a dir.copy() gives Error 12 (can't open the file).
Not even the ResourceSaver.save() method worked.
I also know that the problem is probably linked to the fact that Resource loading is different from the file system API itself and that there are automated instances that manages the resources allocated at runtime, but I cannot find any documentation or clue on how to de-allocate the old font resource before overwriting on it in runtime.
I've tried loading the resource without caching and deleting, at runtime, every node that uses that resources (since the Resource itself should be de-allocated automatically as long as every node that contains a reference to it has been freed) but this did not change at all the errors I'm getting.
If I manually delete the file (when the game is not running) and try loading the new font, everything works, so the problem is surely related to the resources not being de-allocated after it has been loaded at startup.
I don't even have the alternative of the file system API since there is no way to read a .ttf file and getting the Resource through those methods.
Any help of any kind? Did you had a problem like this and found a trick or some sort of workaround? At this point I'm totally lost.