- Edited
I spent all day trying to ¡figure this out and failed.
I made a custom resource called CharactersPack which has a characters_array. I don't want this to ever be empty, so I check in init() if it's empty and add 1 character if it is. So I tested it with loading an empty resource, but something is emptying the array right after init.
extends Resource
class_name CharactersPack
@export var characters_array : Array[Character]
@export var pack_ID: int
var tester : int
func _init()->void:
characters_array.append(Character.new())
pack_ID = 33
tester = 39
Using a setter I noticed that characters_array, pack ID and tester are all receiving the new values. But right after _init() something is changing the values of characters_array and pack_ID back to their initials [] and 0.
Tester is maintaining the new value (39). The only difference with the other two variables is that I never declared tester with a value. This started happening to pack_ID after I gave it a value and then deleted it.
So I looked at the resource file in VisualStudio and found this:
[gd_resource type="Resource" script_class="CharactersPack" load_steps=3 format=3 uid="uid://cplv1g7v0xojk"]
[ext_resource type="Script" path="res://Game/resources/characters_pack.gd" id="1_tumet"]
[ext_resource type="Script" path="res://Game/resources/character.gd" id="2_r71wj"][resource]
script = ExtResource("1_tumet")
characters_array = ArrayExtResource("2_r71wj")
pack_ID = 0
I see characters_array and pack_ID here, but not tester. So I added "tester = 0" and tried it out, but it was removed from the file.
Is this a cache bug, or is there something I'm not understanding about the instantiation process? Thank you in advance!