I JUST got it working! I spent hours trying to figure out what was wrong!!!
As mentioned above, the fix is to select your asset and “Copy reference”, then paste that into your CSV data table within triple quotes.
Make sure your asset witihn the struct is reference by a TAssetPtr<>()
Apparently, and this is NOT documented, the assets have a file extension which needs to be included in the reference path. is my CSV file:
,CreatureName,MeleeDamage,RangedDamage,Range,MovementSpeed,Health,Armor,Portrait,FlavorText
0,Knights,2,0,0,8,20,1,"""Texture2D'/Game/Assets/Textures/Characters/KnightPortrait.KnightPortrait'""",We are the knights who say nay.
1,Peasants,1,0,0,6,10,0,"""Texture2D'/Game/Assets/Textures/Characters/PeasantPortrait.PeasantPortrait'""","Herp de derp, into the breach sir?"
2,Archers,1,2,12,5,10,0,"""Texture2D'/Game/Assets/Textures/Characters/ArcherPortrait.ArcherPortrait'""",Arrows Away!
is my struct:
/**
* These are the per creature properties which we will use to initialize a creature.
*/
USTRUCT(BlueprintType)
struct FCreatureData : public FTableRowBase
{
GENERATED_USTRUCT_BODY()
public:
//FCreatureData();
//This is the creature ID lookup. Same as name.
//UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CreatureData")
// int32 CreatureID;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CreatureData")
FString CreatureName;
/** This is how much damage the cretaure does in a melee attack */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CreatureData")
int32 MeleeDamage;
/** This is how much damage the creature does in a ranged attack */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CreatureData")
int32 RangedDamage;
/** This is how far the creature can shoot its ranged weapon */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CreatureData")
int32 Range;
/** This is how fast the creature can move across the landscape */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CreatureData")
int32 MovementSpeed;
/** This is how much health the creature is allowed to have */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CreatureData")
int32 Health;
/** This is how much armor the creature has. */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CreatureData")
int32 Armor;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Transient, Category = "CreatureData")
TAssetPtr<UTexture2D> Portrait;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Transient, Category = "CreatureData")
FString FlavorText;
};
Header File:
UCLASS()
class UMageMaster2Instance : public UGameInstance
{
GENERATED_BODY()
public:
UMageMaster2Instance(const FObjectInitializer& ObjectInitializer);
//A persistent turn counter
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Game Data")
int32 turnCount = 0;
/*Fetches all unit and creature data for the given unit ID.
@param UnitID - The unit ID to lookup
@param OutUnitData - The unit template data
@param OutCreatureData - The creature template data
@return true if we were able to find a valid unit, false if not.
*/
UFUNCTION(BlueprintCallable, Category = "Unit")
bool GetUnitData(int32 UnitID, FUnitData& OutUnitData, FCreatureData& OutCreatureData);
private:
UPROPERTY()
UDataTable* UnitLookupTable;
UPROPERTY()
UDataTable* CreatureLookupTable;
};
**.CPP file:
**
#include "MageMaster2.h"
UMageMaster2Instance::UMageMaster2Instance(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
ConstructorHelpers::FObjectFinder<UDataTable> UnitDataTable(TEXT("/Game/Assets/GameData/UnitData"));
ConstructorHelpers::FObjectFinder<UDataTable> CreatureDataTable(TEXT("/Game/Assets/GameData/CreatureData"));
UnitLookupTable = UnitDataTable.Object;
CreatureLookupTable = CreatureDataTable.Object;
}
bool UMageMaster2Instance::GetUnitData(int32 UnitID, FUnitData& OutUnitData, FCreatureData& OutCreatureData)
{
bool a = false, b = false;
OutUnitData = *UnitLookupTable->FindRow<FUnitData>(*FString::FromInt(UnitID), TEXT(""));
if (UnitLookupTable != NULL) a = true;
OutCreatureData = *CreatureLookupTable->FindRow<FCreatureData>(*FString::FromInt(OutUnitData.CreatureDataID), TEXT(""));
if (CreatureLookupTable != NULL) b = true;
return a && b;
}