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
editResources
editThese 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
editCommonly 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
File
editFiles 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
editXml is a simple file format, but hard to parse. See XMLParser.
- Pros
- Widely supported
- Cons
- Hard to parse
Scenes
editThis 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- Prior to Godot 4.0, file sizes cannot be larger than 24Gib (gigabytes).
- 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.
- Getting started [ ]
- Making it work
- Making it look good
- Advanced help
- Miscellaneous