Add rows to UDataTable at runtime with c++ code

I am currently developing a plugin on the basis of the c++ API of Unreal Engine. Unfortunately I’m stuck at one point and can’t get any further. What I want in short: I want to read out XML files, create Datatable assets from that data and use this datatable assets on gameobjects later to manage some behaviour. All of that should be done at plugin runtime, i.e. when the plugin is executed. I am already able to receive data from a specified XML file and to create and register a UDataTable asset, so that it appears in the Content Browser and assign a UScriptStruct to it. But how do I add new rows to this table? The documentation is not particularly informative at this point. I found the AddRow() function, which sounds like it would do what I want. However, this function expects an FTableRowBase instance next to the name of the new row and I don’t know how to add data this way. FTableRowBase only has a default constructor. If I use this and use the created instance as a parameter in AddRow(), I can’t open the created Datatable asset anymore (Unreal Engine crashes with an error message that a memory address can’t be accessed anymore). Another idea of mine was to use the UScriptStruct I assigned to the UDataTable asset, thinking that all Row structures must inherit from FTableRowBase. However, then there is a compiler error.

I really hope someone can help me to add data to my empty datatable asset using the c++ API.

Take a look at DataTableCSV.cpp, specifically FDataTableImporterCSV::ReadTable(). It’s constructing table rows from CSV data using the table’s script struct.