TArray of Structs, populating via GetAllRows (UDataTable)

Hi all,

Simple C++ Q for you…

I’m defining a TArray of UStructs in my header file like this:

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Data")
TArray<FStarMapDataLookupTable> OutAllRows; // TArray to hold the outputted rows -> of STRUCT type

Then in the .cpp file i’m trying to populate this array with data from my DataTable with:

StarMapLookupTable->GetAllRows<FStarMapDataLookupTable>(Context, OutAllRows);

I’m getting the following error whilst compiling:

'void UDataTable::GetAllRows<FStarMapDataLookupTable>(const FString &,TArray<FStarMapDataLookupTable *,FDefaultAllocator> &) const': cannot convert argument 2 from 'TArray<FStarMapDataLookupTable,FDefaultAllocator>' to 'TArray<FStarMapDataLookupTable *,FDefaultAllocator> &'

If I define the TArray within the .cpp file in the function it compiles fine. As I’ll be using this TArray in multiple functions i thought it would be best to define it in the .h file and populate it once in BeginPlay()

Any help greatly received… cheers, Matt.

Look on error more carefully, function wants array of FStarMapDataLookupTable pointers not direct data structures, notice the * in type he expect you to use. You will need to make diffrent array with FStarMapDataLookupTable* type and manually copy content that pointers point to your array.

GetAllRows works that way to avoid needless massive data copy in to memory, so it only gives you pointers to that data and if you want you can copy it. But i would say it not recommended because you just doubling memory usage for that table or else you want to have 2nd version of table to edit independently

1 Like

Ty! That is what i was looking for!