One inventory but different item categories.

Hello,

Inventory questions are often asked, but not as much as I thought it would be. Not to mention there are a lot of different kinds of inventory system.

My question is: if I have several categories of item (with different variables), all herited from one Main_Item_BP, what would be the best way to still have a single inventory array and still getting acces to the specific variables from those categories?

I’ve tried to registrer the Main_Item_BP, but I can’t get access to the variable. In my inventory, I’ve tried to put a general structure that would change depending on the item type, but that’s impossible. I’ve tried to work on the Main_Item_Class, but I can just access the main variable and, anyway, I cannot work with the proper references to the items.

So I’ve even tried to still keep the class and then to work with datatables and putting the RowName in the Inventory_Struct, so I could loop and run through the datatable and find the good item… But it was quite a mess.

So yeah, just wondering what’s the best way to implement it.

Thanks.

I don’t think there’s a ‘best’ way, but this looks pretty good. Uses a BP hierarchy and makes things ‘inventorisable’ using a component:

Thanks for the link. It did not really showed how to make a new BP_Item_Weapon and how to access its variables for instance, but with his setup, I managed to do it anyway.
And I learned that “for loop” is way better than “for each loop” while giving index to your slots since you can start at 0. I managed to clear a bit of the mess I had with that.

@IlliciteS
I have a main_item (parent class) that I use to create subs for different types of items. The only variables this class has are ID and Type (enum: weapons, throwables, gear, consumables, ammo etc.). From there I create a child class for each Item Type. Each type has its own specific data structures.

So basically on pickup [interact, bp interface] I check the item type and process the item through a specific event.

  • Type = weapon -> process weapon [event] -> cast to weapon -> get weapon_config (struct)
  • Type = throwable -> process throwable [event] -> cast to throwable -> get throwable_config (struct)

The inventory system (actor component) structure is what matters in the end.

My characters can have 2 primary weapons (guns), 1 pistol, 1 nade, 1 melee weapon in preordained “slots”. Each of these specific items will be spawned and carried on the character (visible). Because of this I can use an Object reference for them in my inventory.

e.g. Inventory
Primary Weapon Slot (Weapon Object Reference) … config struct subtype [smg/lmg/ar/dmr/sr]
Secondary Weapon Slot (Weapon Object Reference) … config struct subtype [smg/lmg/ar/dmr/sr]
​​​​​​​Pistol Weapon Slot (Weapon Object Reference) … config struct subtype [pistol]
​​​​​​​Throwable Slot (Throwable Object Reference) … (smoke,frag,flash,moly)
​​​​​​​Melee Slot (Melee Object Reference)

Loose bag items like consumables, ammo, extra throwables etc don’t have heavy struct configs, just simple identifiers (in most cases). Most of which are stackable. Those are stored in a “Bag” Struct with specific slots (element) for each type. Some elements of the struct are structs, struct arrays etc.

e.g. Bag Struct

Ammo (struct)
9mm (struct) : Total(int), Stacks (TMap): ID(int), count(int)
45ACP (struct) : Total(int), Stacks (TMap): ID(int), count(int)
5.56 (struct) : Total(int), Stacks (TMap): ID(int), count(int)
7.62 (struct) : Total(int), Stacks (TMap): ID(int), count(int)

Throwables (struct)
Frag : count(int)
Smoke : count(int)
Flash : count(int)
Moly : count(int)

Meds (struct) … aka consumables
Med kit: count(int)
First Aid kit: count(int)
Bandage: count(int)
Adrenaline: count(int)
Pain Pills: count(int)

​​​​​​​etc.

2 Likes

Thank you for your answer, looks like a good way to get the structure of different kind of items. I’ll try that.