Skip to content

Instantly share code, notes, and snippets.

@henriiquecampos
Last active May 6, 2021 19:56
Show Gist options
  • Save henriiquecampos/8d98f0660da499967d41c32988cd3612 to your computer and use it in GitHub Desktop.
Save henriiquecampos/8d98f0660da499967d41c32988cd3612 to your computer and use it in GitHub Desktop.
A very, versy simple way to save and load games in Godot Engine
extends Node
func save_game():
var scene = PackedScene.new()
scene.pack(self)
ResourceSaver.save("user://save_01.tscn", scene)
func load_game():
var scene = load("user://save_01.tscn")
get_tree().change_scene_to(scene)
@NathanLovato
Copy link

You don't want to put this on every node. Instead, you can turn it into a reusable node that you put around the root of your main game scene:

func save(branch, save_id):
    var scene = PackedScene.new()
    scene.pack(branch)
    ResourceSaver.save("user://save_%s.tscn" % save_id, scene)
	
func load(id):
    var scene = load("user://save_%s.tscn" % id)
    # change scene or return the loaded scene

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment