+2 votes

Hello,
i'm trying to create a saving system using custom resources: each node has a "stats" resource, that will be saved with ResourceSaver, a relatively simple task for variable like float or strings.
However, some of the stats of these nodes are actually link to other nodes (e.g: each Nation has a city_list variable, which is an array of objects that point to the city nodes belonging to that nation), and i do not know how to put them in the custom made resource i created.

In fact, extending Resource, inside the nation stats city_list cannot be an array of nodes (not possible inside a resource), neither an array of objects (possible, but it cannot be saved).
I was thinking about changing city_list into a list of paths that point at the saved resource file of the city, but it seems like things would spiral up in complexity in this way.

Am i missing something that would make this task easier?

Godot version 3.3.2
in Engine by (1,436 points)
edited by

2 Answers

–1 vote

you could try using json

by (52 points)

Care to elaborate?
I've read Json are more complex to use as save files actually, cause they don't support many variable types

+1 vote

It seems there is no way to store a node inside a resource, so my workaround is to store the tree path of the node instead.
Whenever i got a resource of the type var node=get_node(path), if i need to save it in a resource i actually store it as path

It works, but during save game loading it requires 2 step:
1) instance all the nodes that you saved + load the resources and "put" them in the instanced node
2) when finished instancing ALL nodes, go through them again and get the linked nodes through path (var node=get_node(saverResource.path)

This is because, if you dont wait for all nodes to be instanced, some of the nodes might not be instanced yet

by (1,436 points)
edited by
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 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 webmaster@godotengine.org with your username.