Why is My Inventory slots Array Empty in Godot 4.4.1 Resource?(Solved)

Hello everyone,

I’m working on an inventory system for my RPG in Godot 4.4.1 using GDScript. My Inventory class (extends Resource) has an array of InventorySlot resources, which I initialize with 15 slots. However, when I call the insert function, slots.size() prints 0, even though I expect it to be 15.

Code

inventory.gd

extends Resource

class_name Inventory

signal updated

@export var slots: Array[InventorySlot]

func insert(item: InventoryItem):
	for i in range(slots.size()):
		if !slots[i]:
			slots[i].item = item
			break
	
	print_debug(slots.size())
	
	updated.emit()

inventorySlot.gd

extends Resource

class_name InventorySlot

@export var item: InventoryItem
@export var amount: int

How many items will be inserted, if slots.size() is 0 at the beginning of insert?

The Inventory system has 15 slots, each capable of holding up to 5 InventoryItem objects. I’m initializing the slots array with 15 InventorySlot instances in the Inventory resource.