I have a player character who is supposed to read from an external .csv file and populate an array of skills. The .h file features an FTableRowBase subclass to hold the starting data of each skill:
USTRUCT(BlueprintType)
struct FSkillData : public FTableRowBase
{
GENERATED_USTRUCT_BODY()
public:
FSkillData()
: DisplayName (TEXT("DisplayName"))
{}
/** Extra HitPoints gained at this level */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=SkillData)
FName DisplayName;
/** Icon to use for Achivement */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=SkillData)
TAssetPtr<UTexture> SkillIcon;
};
In the character’s constructor, the following code does the actual population operation:
// Get data table before assigning values
static ConstructorHelpers::FObjectFinder<UDataTable>SkillData_BP(TEXT("DataTable'/Game/Data/SkillTable.SkillTable'"));
DataLookupTable = SkillData_BP.Object;
if (DataLookupTable)
{
// Key value for each column of values
static const FString ContextString(TEXT("GENERAL"));
// o-- Search using FindRow. It returns a handle to the row.
// Access the variables like GOLookupRow->Blueprint_Class, GOLookupRow->Usecode
FSkillData* GOLookupRow = DataLookupTable->FindRow<FSkillData>(TEXT("DisplayName"), ContextString);
if (GOLookupRow) // Only attempt to populate skills list if valid data is found in the table.
{
uint8 SkillsCount = DataLookupTable->GetTableData().Num(); // The skill count will always be far less than 255, otherwise the game will be far too complicated!
for (uint8 i = 0; i < SkillsCount; i++)
{
FSkillData* SkillData = DataLookupTable->FindRow<FSkillData>(FName(*FString::FromInt(i)), ContextString, true); // TODO: Fix this so that SkillData gets pulled properly
// Do some Stuff with SkillData, but only if it is valid.
if (SkillData)
{
UCharacterSkill* Skill = NewObject<UCharacterSkill>();
Skill->SetName(SkillData->DisplayName); // Stick to the first column and get each name under it for each and every skill.
Skills.Add(Skill);
}
}
}
When I run the code with breakpoints in Xcode, the for loop that iterates through the skills in the table works in the sense of iterating through SkillCount, but SkillData isn’t being initialized within it. Is there a problem in my code, a problem with how my .csv file is formatted, or a combination of both issues?
For the record, I have a .csv that looks like this:
,,,,,,,,
,Agility,Stealth,Pistols,Assault,Sniping,Hacking,Diplomacy,Engineering
DisplayName,Agility,Stealth,Pistols,Assault,Sniping,Hacking,Diplomacy,Engineering
SkillIcon,""" Texture2D’Game/HUD/Icon.Icon""",""" Texture2D’Game/HUD/Icon.Icon""",""" Texture2D’Game/HUD/Icon.Icon""",""" Texture2D’Game/HUD/Icon.Icon""",""" Texture2D’Game/HUD/Icon.Icon""",""" Texture2D’Game/HUD/Icon.Icon""",""" Texture2D’Game/HUD/Icon.Icon""",""" Texture2D’Game/HUD/Icon.Icon"""
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
Its formatting is probably way off due to the way it’s formatted in Numbers.