Retrieving similar information from different structs

Hi,
So I’m working on an inventory system and I have a struct that has all of the basic information of the item. I also have in that struct a data table row handle which I want to be used to reference other data tables. I wanted to make a data table for all of my weapons and a data table for all of my potions and so on. The problem I’m having is accessing that information from the data tables. If I use the row handle, how could I grab the correct data table based on the type (enum I created which is also in the item struct).


I know I could fix this problem by just adding in however many data table row handles for each type of data table I wanna grab, but I was hoping this way would be cleaner because I could keep all of the weapon info in one table, an armor table in another, a consumable in another, etc. Any ideas around this would be greatly appreciated!

For extra attributes you could do a json serialization to a string field

@3dRaven thanks for the response!
Maybe I’m just not sure how I’d do this how this would work, but could I make a function that can return a struct based on a select node? I’m not sure if this is complicating things. Basically my goal would to have a data table of every gun in the game with all of its attributes filled out and then to just use the data table row handle to select that as what the item is and I can access its information. Like fire rate, spread, range, etc. And maybe have a similar data table of all of the armor pieces with similar type of data but maybe a defense stat and other abilities and I can use that row handle again and select the armor piece from that other data table and use the type enum to specify weapon, armor, etc.

I would add all weapon, armour prefixes / suffixes to a string value because:
a) you can easily serialize - de-serialize them to needed nested structs on the fly
b) you can have varied amounts of them

You would need to get the row from the datatable and put it through a de-serialization process that would rebuild your weapon with all of it’s stats and modifiers.

And do the reverse on save to datatable of a new permutation

OFC common parameters go straight into the datatable.

Edit: Could you expand on why you would need the select node to determine the struct? Why not soft reference a struct directly in the datatable?

If you use row handles, you can use a Switch On node from the type enum to steer the execution to the correct datatable and do any type-specific things.

That’s what I was thinking. Do you think it would make sense to give the item struct a bunch of other structs that reference the weapon data, armor data, potion data, etc? And Just based off the enum, grab the data that I need or is there another way to do it?

Generally speaking, it’s best to have as little info as possible in the item struct used by the inventory array/maps. Not only does this cut down on storing redundant info, but it’s potentially less things to break and refactor if one of the secondary structs needs changing later on.

In my current project, for instance, my inventory slot struct only has the row name, item type, and count. Stats are only looked up when using/equipping an item or constructing/refreshing an inventory or loot info widget. Likewise things like max stack size are only loaded by the inventory manager component when it adds items.

Whether the inventory structure itself has more or less data is up to how much and how often the info is needed. EG, does the AI need to know spread value for every shotgun or axe it owns every frame to decide which one to use? Or is the info only relevant when actually equipped or in a pause menu? Similarly, does the game always need to know all potion values for either the AI or a “use best potion” hotkey?

Like, since you’ve got item rarity, having that in the struct makes sense so you can get the relevant color for borders and such fast without looking up the whole table. But if your inventory menu is super detailed and is looking up all the things either way, you could just get the rarity along with everything else.

Or, in reverse, if your inventory UI is rather spartan like Skyrim, you could even skip having stuff like icons or meshes in the struct, and only grab them when equipped or selected for “inspection” or whatever.