I made a mistake. What should I do?

Node export is only supported in Node-derived classes, but the current class inherits “Resource”.

extends Resource
class_name InventoryData

@export var slot_datas :Array[SlotData]

What would you like to achieve ?

“I am currently working on implementing the knapsack system. I have created an InventoryData class to manage the inventory, and the code “@export var slot_datas :Array[SlotData]” represents each cell in the knapsack. However, I encounter an error when attempting to execute it.”

what is the error you are encountering ?

I’m wondering if you need to put = [] at the end? do you have an error for use to look at?

@export doesn’t make any sense with a Resource type (any any type other than something Node-based). It reveals the variable to the editor which allows editing it outside of code when it is placed in a scene tree (where, as the docs say, this edited value will then get saved with the scene).

Anything that doesn’t inherit from a node doesn’t have visibility in the editor like that due to simply not being able to be added directly into a scene tree. So why would you need @export? Just remove that keyword, you can still give the variable a default value through code like mentioned above, if needed.

That’s not true, there are many uses for resources. Meshes sprites and shaders use resources.

In this case you would use the filesystem to place resources on the node.

Hm… you are right, I stand corrected. That totally slipped my mind.

I just made a quick test-project as well to test exporting values w/ resources (and then exporting a variable to contain that resource in another node) and it worked cleanly. I could attach my custom resource and the exported variables worked fine as well as running the project.

This was in Godot 4.2. I think your problem @world , is that your array is being typed to contain a resource that inherits from “Node”. I’m assuming SlotData is a custom class inheriting from the “Node” (or derived) class.