I’m making an inventory system and I got stuck on making data values for my items. I want to store preset properties like the default item weight or sharpness for each one of my items but I don’t know what the correct way of doing so is. Thank you in advance!
Well common approach is to use either DataTables or DataAssets sometimes mix of both/more depending on the design needs.
DataTables : Basically you can create ItemDictionaries and Items in it and store them (static)
DataASset : It’s like structs, FItemDefination
To start with depending on the game the defination of item can be many, I suggest going with categories too (Equipment, Consumable, Reagent, Ammunition)
Here is a table data driven simple approach.
DisplayName
Weight
Sharpness
Icon
WorldMesh
Category (Equipment, Consumable, Reagent, Ammunition, etc.) // Enums are good
The more granular design it has its better so its pattenized.
After populating (looting, getting, rewarding) player’s inventory with items, simply you can save structs of inventory data in your SaveGame. For save game this tutorial is something extendable in its own terms.
There are two solutions that come to mind.
Data Table | Unreal Engine 5.7 Documentation | Epic Developer Community
Data Assets in Unreal Engine | Unreal Engine 5.7 Documentation | Epic Developer Community
One thing I have seen that I would avoid: Avoid having a large amount of master classes that use lots of modified class defaults to achieve this. This makes it hard to efficiently edit properties as well as makes you check out assets just to change numerical/data values (If you are using source control)
That’s true and good addition.
As a side note: both has its downsides and upsides.
Data tables are generally good with stats however direct referencing assets like mesh etc, not the best thing. So mix of both is good.
A personal recommendation as design principle : Item & ItemStats would be much much better if they work seperate (structs, data whatever) since one item can have multiple stats, can need change, update so that keeping stats in Json more easy managable like data tables is recommended still have to mention it’s my taste.
Absolutely. A good case study of something like this would be how MOBAs or frequently updating balancing games handle stuff like this. They actually update their information from JSON requests on web. So they are realtime and able to edit any properties/stats on the fly without touching anything inside editor/game code.