Save game as binary resource

Godot Version

v4.2.1.stable.official [b09f793f5]


I’ve seen a few tutorials floating around on how to create saving/loading systems for people’s games, and most of what I’ve seen suggest creating a save file resource (.tres) and saving it to the user directory.

This sounds find and all, but I was wondering if there is a way to save the resource as binary so it wouldn’t be too easy for anyone to just open a file and edit stuff around (It should in theory also allow it to save and load from disk faster?). I saw in ResourceSaver — Godot Engine (stable) documentation in English that it’s possible to save as a .res, and ideally I would want my save system to use .tres in debug/testing, and .res on exported/released projects. Is that possible?

Have you read this?

Saving a file as binary doesn’t necessarily also mean it’s encrypted, as hinted in your post, it just makes it slightly harder for the average player to access the data written to it.

There’s a rather nice tutorial which might be useful as a base, or starting your own research into the topic, since the end solution will always depend on your specific use case. Hopefully this helps!

However, keep in mind that no solution is going to be perfect. Players WILL be able to access the data in your save file one way or another. What you can do, is make this process as difficult as possible, without spending too much development time and resource on it.

1 Like

I’ve updated the post to not confuse binary with encryption.

You can use OS.is_debug_build() to differentiate between debug builds and release builds.

1 Like

Saving as binary is mostly something that should be seen as a way to improve save/load performance and reduce file size, as it’s trivial to create a save editor for Godot formats (which are publicly documented). Even if you use the File class to roll your own binary format, Godot’s binary serialization APIs are also publicly documented and its source code is available :slight_smile:

File and ConfigFile have methods to save/load encrypted files if you need that, but remember that the user may be able to retrieve the encryption key with relative ease.

1 Like

Even if it’s very easy to create a save editor for godot games, it’s fine with me as long as people can’t just open the file directly in notepad and freely edit around with zero effort.

Also if it increases performance and reduces filesize then that might as well be the reason for doing this, so this sounds like what I would want