How to keep instance's data after reinstancing?

Godot Version

Godot 4.4

Question

I’m making an inventory system. I have an array of slots, that contain items.
Slot is a class that contains an item (BaseItem) or null.
My logic goes like this: if selected slot contains an item, instantiate a scene that item belongs to. When switching items, QueueFree that instance.
I’ve run into a problem when I added a flashlight with an energy amount. Whenever I switch and instantiate flashlight again, energy amount is at the default level.
I’ve seen people saying that you need to make an instancing method and pass arguments you want scene to instantiate with. Is this really the only option?
Since I can store that data in BaseItem class, seems like there should be a better option, because that would require storing data somewhere else outside the item’s class.

Problem solved, for those who wonder.
The problem was, that I kept the default instance of BaseItem in my Slot. I just replaced the BaseItem in Slot with the instance every time I instance item.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.