Let's talk loot

Here’s what I do for my inventory system. Every item only ever has the same struct so it can be stored in a array. You store the minimal information to find the item, not the whole item’s information.

struct FItemInfo
{
	FName ItemID;
	int32 MaxStack = 1;
	int32 Quantity = 1;
	TEnumAsByte<EItemType> ItemType;
};

Use the ItemID to find it in the DT_ItemType (DT_Weapon/DT_Armor/DT_Consumable). Your system has weight so you may want to do more calculation moving around containers beside quantity.

Container loot generation would use ItemID/Quantity/SpawnChance to generate loot array. I make several DataTable for different container with rows like

struct FRandomItem
{
	FName ItemID;
	int32 SpawnWeight = 1;
	int32 MinAmount = 1;
	int32 MaxAmount = 1;
};

1 Like