GraphEdit how to save nodes tree?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By websterek

Hi!
I’m writing Godot tool for editing enemies in my game. Node approach seems to be the best option (and better than my actual table editing).

First part works flawlessly (saving values to arrays) but I have problem: how can I save GraphEdit for latter editing? Should I make it from scratch saving all nodes with offsets, values etc. to some file or there is some more convenient and simple method for that?

can any one can give a demo?

huahuapro | 2020-03-04 00:44

:bust_in_silhouette: Reply From: Zylann

If you want to save exactly the whole branch under which your graph resides, you could try setting the local root as the owner of all graph nodes, and then use PackedScene functionality: PackedScene — Godot Engine (3.0) documentation in English
Please note that this will only save what the editor would usually save. So for example, non-exported vars won’t be considered.

I’d like to mention that, on the other hand, you can indeed save your own format manually, which is a lot more tedious but in some cases it’s more correct because what you want to save is not an edited Godot scene (which may include a lot of things you don’t care about or sometimes can’t even be saved), but a graph for enemies. To better illustrate what I mean here, let’s say you have a spreadsheets app implemented in HTML5. To save a spreadsheet, would you save the whole HTML DOM tree with a JS dictionary? Or would you save an ODS/XLS file?

So there is indeed a simple way to save nodes, just pick the method that you think is better for you :slight_smile:

I fixed this error by replacing an exported PackedScene to a non-exported hard-coded path to the .tscn file in my graph node.

I maintain that this is a confusing error to throw. A more descriptive error than “bug?” would be better.

I am setting the owner property in all child graph nodes to the graphedit

    // packed scene
    data.BehaviorGridEditScene ??= new PackedScene();
    foreach (var child in GetChildren().OfType<GraphEdit>())
        child.Owner = this;
    var error = data.BehaviorGridEditScene.Pack(this);

but I’m still getting the vague error

ERROR: Resource was not pre cached for the resource section, bug?

The saved packedscene doesn’t contain any nodes aside from the default instantiated “new” scene, which I suppose is too odd to not investigate on my part.

If nothing else, I know that this is not a good enough error message from Godot. :slight_smile: