Godot Version
4.6
Question
i need help trying to load game, ive followed a tutorial on how to make a save load system in godot using resource class, it saves the data to a .tres file but it doesnt load. for now im trying to get the players position to load, but later ill also add inventory, stats etc.. function save() is added to the main scripts process() function, load() is added to ready() function
extends CanvasLayer
const PATH = "user://scene_data.res"
@export var player: Node2D
func _save() -> void:
var data = SceneData.new()
data.player_position = player.global_position
ResourceSaver.save(data, PATH)
func _load() -> void:
var data = ResourceLoader.load(PATH) as SceneData
player.global_position = data.player_position
#this is a seperate script with snene data
extends Resource
class_name SceneData
@export var player_position : Vector2
Is it not recommended to use resources to save games, as it has some security issues.
Also we don’t know what guide you followed.
1 Like
Take a look at my Disk Plugin and see if that will solve your problem. It’s very lightweight. Basically you’d download and add it (step-by-step instructions in the link.)
- Add your Player Scene to the Persist group.
- Add a
save_node() function to your player:
func save_node() -> Dictionary:
var save_data: Dictionary = {
"global_position": global_position,
}
return save_data
- Add a
load_node() function to your player:
func load_node(save_data: Dictionary) -> void:
if save_data:
global_position = save_data["global_position"]
- Call
Disk.save_game() anytime, anywhere in your code, and the player will save.
- Call
Disk.load_game() anytime, anywhere in your code, and the player will load.
1 Like
@dragonforge-dev
OT:
In your documentation you are missing a “m”:
containing ultiple setting values.
1 Like
Thank you @conz3d ! I actually started updating the documentation to add some examples like this in because @Dad3353 mentioned it to me too. Fixed it!
2 Likes
Disk v0.8 released. No changes to the code, but I added in better instructions in the Readme with screen shots and a new example in the test project. Next version will probably be v1.0 and I’ll release it to itch with a better looking test project.
1 Like