
Publisher
steffenschumacher
Nested saving and loading
Nested saving and loading plugin for Godot 3.5 is a small library (only 131 lines of code) which implements saving and loading with the possibility of saving nested Nodes, which each have their own distinct state.
This plugin has been mirrored from the Godot Asset Library.
The plugin author is in no way affiliated with Gadget.
If you are the author of this plugin and would like this mirror removed, please contact support@gadgetgodot.com.
Nested saving and loading plugin for Godot 3.5
Explore the docs »
Report Bug
·
Request Feature
Table of Contents
About The Project
Built With
Getting Started
Installation
Usage
Contributing
License
Contact
About The Project
Nested saving and loading plugin for Godot 3.5 is a small library (only 131 lines of code) which implements saving and loading with the possibility of saving nested Nodes, which each have their own distinct state.
(back to top)
Built With
The addon is made 100% in GDScript.
(back to top)
Getting Started
The plugin is made for Godot 3.4.x and 3.5.x
Installation
- Clone the repo
git clone https://github.com/steffen-schumacher/godot-nested-saving-loading
- Copy the 'addons' folder into your project root
- In the Godot Editor go to Project -> Project Settings -> Plugins and check the 'Enable' button
(back to top)
Usage
This plugin adds an autoload singleton called Persistence
. Save a scene by calling save_scene
with the tree of the scene and a path. Load the saved state back into the scene by calling load_scene
with the same parameters.
Property | Type | Description | Default value |
---|---|---|---|
default_properties |
Array |
Default properties to save | [] |
save_position |
bool |
Should the position be saved | true |
save_rotation |
bool |
Should the rotation be saved | true |
Example call that saves the current scene:
Persistence.save_scene(get_tree(), "user://savegame.save")
Example call that loads the state into the current scene:
Persistence.load_scene(get_tree(), "user://savegame.save")
To make Nodes in the scene persistent, add them to the group Persist
. By default, the position and the rotation of Spatial and Node2D extending Nodes will be saved and loaded. If the Node does not extend one of these classes, only additional values will be saved. You can add a function called _save()
to your persistent Node, to save additional values. These will get assigned each to the property with a matching key when loading the scene.
Example function that saves the visibility of the persistent Spatial or Node2D:
func _save():
return {
"visible": visible
}
Another way of saving additional values is adding the names of the properties, you want to save, to Persistence.default_properties
. You can set these via GDScript or in the inspector by modifying the addons/nested-saving/Persistence.tscn
.
Example configuration that saves the visibility of all persistent Nodes:
Persistence.default_properties = ['visible']
If you want to save nested Nodes, you have to make every Node between the root persistent Node and the child persistent, so the loading system can process the path to the parent Nodes correctly.
Right:
Wrong:
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
(back to top)
License
Distributed under the MIT License. See LICENSE.txt
for more information.
(back to top)
Contact
Steffen Schumacher - steffenschumacher7@gmail.com
Project Link: https://github.com/steffen-schumacher/godot-nested-saving-loading
(back to top)