The issue was larger than I thought:
The ResourceSaver is the one reporting it, but it is the saved resource that causes the bug, After some cross testing, here is what came out:
func create_profile(new_profile: String):
profile = ProfileData.new()
# If the next line is deleted, the bug disappears.
profile.unlock_archetype(GameData.iunctus_archetypes[0])
profile.take_over_path(new_profile)
save_profile()
Well heading to unlock_archetype then:
func unlock_archetype(archetype: IunctusData):
unlock_archetypes.append(archetype.duplicate(true))
# If the next line is deleted, the bug disappears.
unlock_archetypes[-1].level_system = IunctusLevelSystem.new()
From there we have two possibilities, it can be tracked down to the level_system setter:
@export var level_system: IunctusLevelSystem = null:
set(value):
level_system = value
if level_system != null:
# If the next line is deleted, the bug disappears.
level_system.iunctus = self
And here we are at the end of the line.
Setting the field to self cause the ResourceSaver.save to write:
Resource was not pre cached for the resource section, bug?
It is to note that if level_system.iunctus
is set to something else, for exemple IunctusData.new()
it will not cause any issues.
It is the reference to self that seems to confuse the saver.
If we have a look at the saved profile.tres
:
[sub_resource type="Resource" id="Resource_wspf8"]
script = ExtResource("2_q3w88")
iunctus = null
xp_pool = 0
level = 0
current_xp = 0
target_xp = 100
We can indeed see that the field iunctus is null and not a reference like we could hope for.
How can it be fixed
It can be fixed by not assigning to self but by giving a weak reference to it:
level_system.iunctus = weakref(self)
Thanks everyone for the help