I created two resources, ResA
and ResB
:
ResA.gd:
extends Resource
class_name ResA
export var data : String
export var data2 : int
ResB.gd:
extends Resource
class_name ResB
export var data : Dictionary = {}
Then, I created a new ResB
instance and saved it like this:
func _ready():
var buggy = ResB.new()
var res = ResA.new()
res.data = "A1"
res.data2 = 1
buggy.data[res] = [1, 2, 3]
res = ResA.new()
res.data = "A2"
res.data2 = 2
buggy.data[0] = res
ResourceSaver.save("res://data.tres", buggy)
Then, when looking at the saved resource, I found that the resource that was used as a key in the dictionary was replaced with a null, while the resource that was used as a value in the same dictionary was saved. Why does this happen?
The workaround I found is to add another array to the ResB
that will hold all your resources that were used as keys. In that case it will be saved properly.
Also, this is output to console when trying to save:
ERROR: Resource was not pre cached for the resource section, bug?
At: scene/resources/resource_format_text.cpp:1373