Let's say I have a Location resource type. I have hundreds of Locations sitting there in the Location folder. Locations can connect to other locations. For the game to function properly, the entire connection graph between locations must be available at all times, even when most locations are unloaded.
I could make Godot calculate and save the graph at runtime, by loading every location during the game's startup, but it's slow, and it would make much more sense to precompute and save it. But here, I run into a problem.
I have an Editor script that calculates the graph and saves it to disk, with the intention to run it before running or compiling the project:
var graph = ... # calculate graph
var saver = GraphResource.new()
var dir = Directory.new()
This appears to work fine. If I open Graph.tres in Notepad, I can see that it is properly updated to represent the current state of the Locations. However, from inside the editor, the changes are not visible - I can still see the old graph structure - and whenever I save or run a scene, the file reverts back to the old unupdated version. I'm assuming Godot keeps the old version is some kind of cache.
What can I do here? Is there some way to avoid overwriting the file with an older version? Or, maybe, is there a better way to precompute things before runtime?