Guide to the Godot game engine/Saving and loading

Most game engines allow you to save files. Godot is no different.

There are five methods to save files, and each method has at least 1 loading method.

Methods

edit

Resources

edit

These can be loaded with GDScript's built-in load() function. See creating resources for more.

Pros
  • Load and save built-into Godot
Cons
  • Hard to debug

Json

edit

Commonly used for sending data over the internet. It's easy to read and modify, so consider compressing or encrypting your save file to prevent cheats. This is especially important in multiplayer games. Alternatively, save player data in the cloud. This will require setting up a server.

Pros
  • Easy to debug
  • Fast saving/loading times
Cons
  • JSON does not define ints, only numbers. All numbers comes out as a float.

File

edit

Files can be opened and parsed with the File object.

Pros
  • Easy to debug
  • Easy to encrypt to prevent cheaters
Cons
  • Can be hard to parse

Xml is a simple file format, but hard to parse. See XMLParser.

Pros
  • Widely supported
Cons
  • Hard to parse

Scenes

edit

This can be done by calling Node.pack(), which turns it and any child with owner set to it, which can be saved with ResourceSaver.save() and loaded with load().

Pros
  • Built into Godot, can be rather fast
Cons
  • Saves everything, difficult and time-consuming to select what to save
  • Hard to debug

You can exclude a node by setting its owner to null. To include a property, make the property exported. If a node's oowner property to anything other than the node that pack() is called on, it will not be saved. Note that this property will have to be set to anything that is added to the scene by script, as they start with no owner.

Notes

edit
  1. Prior to Godot 4.0, file sizes cannot be larger than 24Gib (gigabytes).
  2. A useful text file format is "csv" (comma separated values), where each value is comma (",") separated. Use String.get_csv() to separate them.

Tips

edit
  • Really large files can take almost a whole minute to load. Consider splitting save files up into more than one, and only load each file when needed.



Guide to the Godot game engine

Getting started [edit]
Installation
What is a node?
Programming
Resources and importing
Signals and methods
Your first game
Making it work
Debugging
Input
Physics
Saving and loading
Multiplayer
Making it look good
UI skinning
Animation
Advanced help
Servers (singletons)
Platform specific
Optimisation
Encryption
Exporting
Plugins
Miscellaneous
Helpful links
Authors and contributors
Print version


<-- previous back to top next -->