I´m using this as an example to iterate through a custom DataTable. The structure is the following:
The Combat Actions are a C++ class which inherites from UObject. What I am trying to do is Iterate through the DataTable, cast each row to an Struct, representing this DataTable structure and store it in a TMap. The cast always fails and returns a NULL.
Struct:
USTRUCT(BlueprintType)
struct FComboTableRow : public FTableRowBase
{
GENERATED_BODY()
FComboTableRow();
/** String of buttons for this combo **/
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FString m_sCombo;
/** CombatAction of the last input of the combo **/
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TSubclassOf<class UCombatAction> m_combatAction;
};
Code:
I have tried to Iterate and Cast in these two ways (in the first one I get the row names correctly):
//First way
UDataTable* pDataTable = LoadObject<UDataTable>(NULL, UTF8_TO_TCHAR("DataTable'/Game/Blueprints/DataTables/Tables/ComboDataTable.ComboDataTable'"));
FString ContextString;
TArray<FName> RowNames;
RowNames = pDataTable->GetRowNames();
for (auto& name : RowNames)
{
FComboTableRow* pRow = pDataTable->FindRow<FComboTableRow>(name, ContextString);
if (pRow)
{
m_hashTCombatAction.Add(pRow->m_sCombo, pRow->m_combatAction.GetDefaultObject());
}
}
//Second way
for (auto it : pDataTable->GetRowMap())
{
FString rowName = (it.Key).ToString();
FComboTableRow* pRow = (FComboTableRow*)it.Value;
m_hashTCombatAction.Add(pRow->m_sCombo, pRow->m_combatAction.GetDefaultObject());
}
Any ideas? Thanks in advance