Hello everyone,
I’m trying to create an inventory system that can store all types of items (a rock, a weapon, a bucket…) in a multiplayer game.
So I started following common tutorials on the internet, and they all work the same way. I created a datatable based on a structure S_Item (ItemID, name, description, mesh). My player has an S_Item array as an “inventory” property, and it works. Each actor in the world has an ItemID, so when I pick it up, I can retrieve all the information and store it in my inventory (S_Items array).
But now, I want my items to be specific or unique. For example, let’s consider a Bucket item. A bucket is a standard S_Item with two extra properties: MaxQuantity and CurrentQuantity of water in it. My question can also be applied to random stats for a weapon, the number of ammo in a gun, or durability on a weapon.
And now starts my endless research for a solution
-
Structure Inheritance
There is no inheritance from structure, so I can’t create a specific structure for my bucket (and other containers) and add it to my inventory’s S_Items array. I could add my two extra properties to the S_Item base struct, but then I would need to add properties for weapons, potions, and so on. In the end, my S_Item would have 500 properties, and 95% of them would be empty.
So, this is not the right solution. -
UObject
Instead of using structures, I tried using UObjects. I can create my S_Item and my Bucket with inheritance. My inventory will be a (UObject) S_Item array and can store everything. But sadly, UObjects cannot be saved, so I can’t use the save game functionality.
This also seems not to be the right solution. -
Data Assets
I saw that data assets can inherit, so my Bucket can be a child of an S_Item data asset. I create my base item and my bucket with inheritance, and I construct an object based on my data asset and add them to my inventory. I can also modify them (change the current water quantity), so far so good. But like UObjects, these actors can’t be saved.
Again, not the right solution. -
Actor
Actors can inherit and be used for my inventory, but actors are spawned in the world, not in my inventory. Idon’t want to put all my items in the world, even hidden. While this may work, it’s definitely a bad way to do it, and it can’t be saved.
Not a good solution either.
The last thing I have in mind, but I didn’t try it because it seems really complicated for what I think is a simple use case, is to use the data asset method (3) and, for all types of data assets, create a matching structure (so duplicate all base properties in dozens of structures). Then, when I save, I have to iterate over every item on the player (but also in all chests, items on the ground, etc.), make a struct depending on the type of the asset to match the item data asset, copy every value, and then save it. My game is a multiplayer game, so I’m going to save hundreds of items, and I wonder how long it will take and how it will affect performance.
After days of research, I’m open to any new suggestions. If you have a tutorial, a post, or something where an inventory can store dynamic items (my example was with the bucket, but it’s also the case for weapon durability, ammo, random stats, anything that makes an item unique in the game), I would love to read it.
Thanks for your help, sorry for the long post and my English