I want state to persist across game sessions. For that, I want to create a save file.
As far as I can tell, there are multiple options for storing, setting, and getting the data on the relevant nodes:
- As properties on the node
- As a Dict, which I can (de-)serialize for the save game.
- As a RefCounted or Resource data container which is a property of the node.
I lean towards 3., as it could encapsulate the (de-)serialization logic with its data. But as a noob I am not sure this won’t lead me in the wrong direction.
I am very new to Godot and I was hoping there is a „battle tested“ simple approach that works most of the time. If so, I’d like to know about it. If not, what do you think about the three possibilities above? Do you know of another, better approach?
Also: how do I track which nodes are the relevant ones? Using a group?
Thank you so much for your time
People mostly use custom resources, as it is most supported and well integrated into the engine option. And as you mentioned it handles serialization for you, so it is the easiest option.
The downside is that resource-based save files are not safe. You can inject arbitrary code into a resource file and it will be executed the moment this resource is loaded into memory. That means that if your players download save files from the Internet, they risk getting trier data/passwords stolen, files encrypted, trojans installed, really anything you can think of.
Edit: here is a link to the issue if you want more details: Provide a way to load resources without running scripts · Issue #4925 · godotengine/godot-proposals · GitHub
Thank you, I didn’t know that.
If I wrote my own (de-)serialization within a script that extends Resource I could prevent executing code and only read/write a (binary) file.
What would you say about that?
The thing is that I could try all approaches and figure out what suits me best, but I am not sure I want to invest that time if other people have already made those experiments and arrived at some conclusion. Plus: that it suits me now doesn’t mean it’s a long-term solution.
I’d be happy to hear about successful/not so successful approaches to this that others have tried already.
Maybe I am too lazy?
I chose the custom resource option. I dont see why someone would download someone else’s save game. just warn them not to.
Thanks. I think I’ll do the same until I am at least in alpha-stage. If I ever publish the game, though, I would want players to be able to safely share savegames.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.