Godot Version
4.5
Question
Hello! I’ve been trying to implement a saving system in my game using custom resources, but whichever way I do it either doesn’t work or throws errors.
So I have a custom persistent data resource, which holds an array of defeated enemies and a Player resource. The player resource holds all player stats, equipped items, and inventory. Every item (equipped and in inventory) has a NarrationLine resource attached to it.
So I’m using a global DataManager script to save and load the game, which looks like this:
var persistent_data : PersistentDataResource
var save_path := "user://data.tres"
func _ready():
persistent_data = load("res://Resources/persistent_data.tres")
load_game()
func save_game():
ResourceSaver.save(persistent_data, save_path, ResourceSaver.FLAG_BUNDLE_RESOURCES)
func load_game():
if FileAccess.file_exists(save_path):
persistent_data = ResourceLoader.load(save_path)
When I tried using this script without the ResourceSaver.FLAG_BUNDLE_RESOURCES, the defeated enemy data within persistent data saved fine (as it is just an array of Strings), but the Player data did not save at all. But now that I added ResourceSaver.FLAG_BUNDLE_RESOURCES, on starting the game it throws an error “Class “NarrationLine” hides a global script class.”
I’m aware there are similar issues brought up before, but I was wondering if Godot 4.5 fixed it or if there is a way to save nested resources without workarounds.
Would be grateful for any help!