+1 vote

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()
saver.graph= graph 
var dir = Directory.new()
ResourceSaver.save("res://path/to/graph/Graph.tres", saver)

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?

in Engine by (19 points)

Please log in or register to answer this question.

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 Frequently asked questions and 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 [email protected] with your username.