What is the best way to store the data about items in an inventory?

For each item in my game i have universal variables that are the same for evry instance saved in a prefabGameobject (might replace this with a json later) ,for example a bronze sword might always have a base attack strengh of 4 however i also have more variables that are item specific, for example the damage its endured, and i need to save this information in my inventory whenever its there

I have 2 main ideas but am open to any suggestions, there may well be a better way than both

1 i could have arrays that store a specific variable for each slot and i copy the data to the relevant index (slot number) in the array to store it , ef if item1 has a String X = turkey; and int Y = 3 ; and item 2 has a string X = sand ; and int Y = 5; then if each array is 4 long and starts with them all empty if i copy item 1 to index 1 and item 2 to index 2 then now String X = turkey , sand , empty , empty and int Y = 3,5,empty,empty , the information can hence be called by getting the value of evry array at the index of the slot you need

2 alternatively i could have an array of gameobjects and each item in the inventory could have a hidden gameobject containing the variables, this could just be the same gameobject that was previously on the ground before it was ‘picked up’ that has now been disabled to stop its usual behaviours of making particles and floating up and down and to stop it showing up in the world, by dissabling the collider it would also no longer be picked up by the itemsToPickup gameobject list in my pickupItem script

Im guessing the latter would be better since it isnt destroying any gameobjects and the data for any variable will still be stored even if i add new variables in the item - id dont need a new array to store any new variables
id appreciate any advice or suggestions :slight_smile:

i hope it made sense if not just tell me

0 replies :(. Did you find a way to do it? I just want to have a matrix which stores some objects of type “Slot” which is just a class that has a enum (to tell what item you have) and an integer value (to tell how many items you have). But I want to have some data on specific items, like how damaged the sword is, what upgrades you put on an item, etc. However I don’t want to make stackable those items like sword which need to store data about them (my inventory would be like the one in Minecraft, where you can’t stack tools or any item with data on it), so I can store the data in the class “Slot”. But how?

Let’s say the sword needs some data of type “SwordInfo”, and “ToolInfo” (let’s say SwordInfo would contain info about how sharp it is, and ToolInfo about how broken it is). I could include those classes in the “Slot” class, but for a pistol you would need another type of data, and I don’t want to have all types of data on the “Slot” class, because it doesn’t seems right (the pistol shouldn’t have “PistolInfo” and “SwordInfo”, just the “PistolInfo” on it).

The way I want to do it is to put a list of “ItemInfo” in the slot class (which could be empty), ItemInfo being a class which stores an enum (to tell what type of info it has) and a byteset which would store the data, but this requires the possibility to serialize each data in a byteset, and deserialize it. Is it possible to do this? Also I am also open to better suggestions

Thanks for reading!!