Issues with saving an Array of Items

Godot Version



I have an autoloaded singleton called “Inventory” that extends Node, which is used by the Player node to load stats from items.
Inventory has an exported variable called “items” that is an Array of “Item” objects.
I also have a “SaveData” object that extends “Resource”, which has an “eq” exported variable that is an Array of “Item”.
All variables in the “Item” object are set to @export. “Item” extends “Resource”
In a “SaveManager” singleton I append 2 items to the Inventory array like this:

func _ready():

The 2 and 3 represent the grade of the weapons (bigger grade = bigger stats).
After that, I create a new SaveData object and set it’s “eq” variable to the “Inventory.items”, after which I save the file as “save.tres”, then load it into another variable to compare the print outputs:

var save_game =
save_game.eq = Inventory.items
print("SAVED: ",save_game.eq), SAVE)
var test : SaveData = ResourceLoader.load(SAVE)
print("LOADED:" ,test.eq)

The console output looks like this:

SAVED: [<Resource#-9223372009843456809>, <Resource#-9223372009826679592>]

And if i remove “.eq” from both prints:

SAVED: <Resource#-9223372009809902373>

The contents of the “save.tres” file:

[gd_resource type="Resource" script_class="SaveData" load_steps=6 format=3]

[ext_resource type="Script" path="res://Items/Torso/" id="1_gk8hu"]
[ext_resource type="Script" path="res://Items/Weapons/" id="2_d4qle"]
[ext_resource type="Script" path="res://Scripts/" id="3_8b00e"]

[sub_resource type="Resource" id="Resource_yd4bj"]
script = ExtResource("1_gk8hu")
itemName = "Assasin Armor"
itemDescription = "ATK +12
SPD +10
DEF +3
+3% szansy na kontre
+3% szans na unik podczas unikania"
itemSet = "Assasin"
sellValue = 8
itemType = "Torso"
itemSubtype = "RogueArmor"
grade = 2
maxGrade = 5
gradeCost = 24
stats = [["ATK", 12], ["SPD", 10], ["DEF", 3], ["CritCH", 7]]
passives = [["Countering", ["RawDodge", 3]], ["Dodging", ["RawDodge", 3]]]

[sub_resource type="Resource" id="Resource_20ut2"]
script = ExtResource("2_d4qle")
itemName = "Super Dagger"
itemDescription = "+20 ATK
 +15% szansy na kryta
 +15% do obrażeń zadawanych przez kryty
 zwiększa atak o 15%
 +15% do obrażeń krytycznych podczas wykonywania ataku alternatywnego"
itemSet = "Assasin"
sellValue = 15
itemType = "Weapon"
itemSubtype = "Dagger"
grade = 3
maxGrade = 5
gradeCost = 36
stats = [["ATK", 24], ["critCH", 15], ["critMul", 0.15], ["ATKP", 0.15]]
passives = [["AltAttack", ["critMul", 0.15]]]

script = ExtResource("3_8b00e")
eq = Array[Resource("res://Scripts/")]([SubResource("Resource_yd4bj"), SubResource("Resource_20ut2")])

Am I doing something wrong when saving or loading the file? Is my approach as a whole incorrect?
What could I do to load this Array of items and then replace the Inventory array with the loaded array?

Don’t use required parameters in Object._init() or it will fail when de-serializing the objects from disk as explained in the documentation.