I’m currently doing this. No need for a database. Just use multiple excel files. I do the joining in code, something like this:
create a TMap, which is a key value pair.
The key is the ID of your object.
The value is a TArray of keys for your other objects.
When you build your TMap, on the first occurence of an object, you create a new key value pair. If the map already contains your key, just insert it into the array of ID’s.
If you need to look up the inventory for an object, all you need is that objects ID. That’s your lookup into the map. Then you get a bunch of ID’s for inventory items. You can then match these ID’s to the inventory items rows in O(1) time.
Here’s my code:
UMyGameInstance::UMyGameInstance(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
DT_Units = Units.Object;
UDataTable* DT_UnitTags = UnitTags.Object;
DT_Skills = Skills.Object;
DT_Tags = Tags.Object;
//we're gonna build a map which contains a unit ID to tag ID lookup, which is going to be a (1:*) relationship
if (DT_UnitTags != NULL)
TArray<TArray<FString>> Data = DT_UnitTags->GetTableData(); //the first record is the row descriptors, so we skip it
for (int a = 1; a < Data.Num(); a++)
int32 UnitID = FCString::Atoi(*Data[a]); //unit ID
int32 TagID = FCString::Atoi(*Data[a]); //Tag ID
Also, it’s possible to create your own hash table based on the “RowData” variable within the DataTable class. It’s publicly available, but you have to do some tricky pointer dereferencing and casting to get at the data (see FindRow<T>() implementation).
You could also use the GetTableData() method, but that will return a 2D array of strings, so you’d have to cast those strings to your data types. Not as clean as an array of structs, right? I was thinking I’d do an engine mod to do this, but I’ve been a bit pressed for time. Maybe on a weekend