Fill array with DataTable

Hi,

I want to fill an array with all the data that a row of a DataTable has. I tried to do this in blueprints but I can’t iterate in a loop over all pins of a certain row. This DataTable was created in the editor and fill by a CSV (excel). This dataTable have only FText multiline fields.

I have done a C++ blueprint callable class that It receives the DataTable pointer and it returns an array with all data found in the row. The problem is that, when I receive the array it have some unwanted data like this: “NSLOCTEXT(”[7AD1145D40F… and after that my own text. It seems something like control ID.

Can I have any way to obtain only the FText?
I tried a lot of different codes, but is difficult to me to understand the structure of dataTable.

This is my .h:

UCLASS()
class SFTB_API UFillArrayByBPDS_Books : public UBlueprintFunctionLibrary
{
GENERATED_BODY()

UFUNCTION(BlueprintCallable, meta = (DisplayName = "Fill Array by dataTableRow", CompactNodeTitle = "Fill Array by dataTableRow", Keywords = "Array DataTable Fill"), Category = SftB)
static TArray<FText> fillArray(UDataTable *book);
};

This is my .c:

TArray<FText> UFillArrayByBPDS_Books::fillArray(UDataTable *book)
{

    TArray<FText> myArray;
    TArray < TArray < FString > > miArrayDataTable;

    int index;            //iterator index
    int rowBook = -1;    //If we found the title, we store the row number here.

    miArrayDataTable = book->GetTableData();
    for (index = 0; index < miArrayDataTable.Num(); index++) {
        if (miArrayDataTable[index][0].ToLower() == "TitanGreeks") {
            rowBook = index;
        }
    }
    if (rowBook != -1)
    {    
        for (index = 0; index < miArrayDataTable[rowBook].Num(); index++){
            myArray.Add(FText::FromString(miArrayDataTable[rowBook][index]));
        }

    }
    return myArray;
}

And this is a part of the output:
Screen Shot 09-25-17 at 11.49 AM.PNG

Any help will be appreciated!

GetTableData() will return the SERIALIZED data.

If you want you can get an structure for each table row if you do the following:

First get all of your table row names using book->GetRowNames(). Then iterate through that array and for each row name get your row struct using book->FindRow<YourStructType>(TheRowName). That will give you a pointer to the struct containing all the data for each row.

Hi Sveitar,

thank you very much for your help.

When I tried to implement the code that you suggested me, other issues happended:

The datatable struct type was declared on the UE editor, not in C++ code. Due of it, I don’t know how can I get the name of the structure for referencing it on the code.
I tried to create other struct with the same amount and name of variables but the compiler show the next error: ‘StaticStruct’ isn’t a member of ‘bpds_books’.

This is the new code:

struct bpds_books {
    FText Title1, Pag1, Title2, Pag2;
};

TArray<FText> UFillArrayByBPDS_Books::fillArray(UDataTable *book)
{

    TArray<FText> myArray;
    TArray < FName > rowNames;
    FString myString;

    int index;            //iterator index

    rowNames = book->GetRowNames();
    for (index = 0; index < rowNames.Num(); index++) {
        book->FindRow<bpds_books>(rowNames[index], myString);
        myArray.Add(FText::FromString(myString));
    }
    return myArray;
}

In fact this is my biggest doubt, if I can use and reference the dataTable created on the Editor in C++ or if I need to undo all my relationships with this dataTable in the blueprints, create the struct in C++, reload the data from the CSV again and redo the relationships in the blueprints.

Thanks for yout patience :slight_smile:

Create the struct in C++ and redo the table, don’t use the BP struct. You shouldn’t try to get BP classes in C++ like that.