How to make an inventory composed of different types of structs ?

So I made an inventory system (based on this serie), it works this way :

  • Each item is represented by a struct (s_IDcards for example, with name, birthdate, adress etc…)
  • My inventory is an array of these structs (lets say it has 16 slots)

This is working well but I’m facing a problem now that I want to have different item types stored in it. These items have different structs than s_IDCard, like for example some wood logs (with a variable “wood type” for example) and I dont see a practical way to do that.

  • If I keep a single array, then the main item struct has to have more variables than I need for each item (name, birthdate, adress, wood type). But this is a problem as UE doesnt like when I modify structs that I use in many BPs

  • I can make 3 arrays of size 16, 1 for s_IDCards, 1 for s_Woodlogs, and 1 array of 16 enum to tell in which of the other 2 arrays the actual item info is stored.

I cant think of an easier/more maintainable way to do this, could you help me on that please ?

thank you

Create a struct which holds an array of your other struct types. I switched from structs to data assets because of

UE doesnt like when I modify structs that I use in many BPs

Honestly it would be much easier to hold the references for objects instead of structs, as there is no inheritance for them. You can proceed with either of your struct options, but if you switch to objects instead, you can just hold any inventory items in the array of the base item object references. The base class would simply be a parent of all different items. You can also easily preload it with some basic universal data (like item id etc.) that is useful for any item type.

Am I in the wrong if I say :
If I use class references then I will have to have a children class for every single new item. I can have a parent class for all items that holds data common to all inventory items (like inventory icon/id/max stacks) so thats handy

But in my example, every ID card will have to be a class of its own, that I create beforehand in the editor. Since we use class references, values cant be modified.

I dont see how I would be able to create new unique inventory items at runtimes with class references

EDIT : nvm, you were talking about actually creating the objects !! ok then that can maybe work !!

Create a struct which holds an array of your other struct types.

Did you mean “Create an array which holds a struct of your other struct types” ?

As for data assets, I’ll look into it, ty !

No, create a struct with your different struct arrays in it. But I wouldn’t recommend it. Go for data assets which contrary to what some might say can be created without the need of C++