Create a Data Table Asset with USTRUCT C++

Okay, I’ve been searching on the internet for a few days but I didn’t found any useful ressource about it… I’ve been trying to make a factory that generates a DataTable when importing my custom file. I’ve created my USTRUCT which is extended from FTableRowBase, I’ve started to implement my factory and I’m able to create a DataTable asset in the editor when I drag and drop my custom file type.

However, my datatable doesn’t have any row, so what i would like to do is to use my custom c++ structure as row names. If I understand well, I need to set the RowStruct variable of my Datatable to my custom struct. But when I try to do so, the compiler says that i need a UScriptStruct variable. But I don’t know how to convert my USTRUCT to this type of variable. Does anyone have a hint about how to do so? Or am I simply doing something the wrong way?

I would be very grateful if someone could give me a good tutorial on how to create an empty datatable with rows using ONLY C++ cause I’ve been banging my head with it lol

Here’s my struct:

And here’s my factory:

1 Like

UStruct* and UScriptStruct* is struct equivalent of UClass* for classes, it part of UE4 reflection system, those objects stores information of code stricture, for both C++ and Blueprint. And yes… you might probably guess it right now… you getting it exacly the same as you do with UClass:

NewAsset->RowStruct = FDislogStruct::StaticStruct();

StaticStruct() as well as StaticClass() is functions generated by UHT before compilation, thats why they are not so visible, not to mention for UE4 structs can’t have functions so it’s not even referenced in API reference, i discovered that myself at random too.

Thanks a lot for the answer, I wouldn’t be able to find it by myself lol Do you have any useful link that can help me fill the datatable using c++? Also, how did you learn all of those things about the engine core code? The documentation is pretty helpful, but I was wondering if there was some kind of book or online ressource that could help me better understand the engine code.

Mainly API reference and engine source code, github searching thru it… plus my intuition :stuck_out_tongue: In general i very good on getting information myself. In case of StaticStruct i find it at random when i didn’t really needed, but it existance isn’t really suppricing considering theres StaticClass in classes.

What you dealing here specifically is reflection system, when you compile down the code all code is either turn in to numbers or is just function as a logical hint for compiler, because of that all code structure information (like classes, function, all the names etc) is lost. Only way to keep that information is to code ability to store that information, UE4 does that using those U* macros (like UPROPERTY, UFUNCTION etc), a tool called UnrealHeaderTool (UHT) reads the code and gethers infmation about those object in the code with those macros as well as specifiers inside them, then it create extra C++ code which get pasted to your code via *.generated.h files and GENERATE_BODY() as well as extra cpp files that you don’t usually see. The end result is set of UField objects that are created when you load your code module containing information about code strucutre, all classes (UClass), strcutures (UStruct) and properties (UProperty) and functions (UFunction, except in structs) that they contain:

And you can gether those using either TObjectIterator or TFieldIterator. It powers all property editors and nodes in blueprints in editor, majority of nodes in blueprint (with f icon) are simple binds in there UFunction object, functions are simply flagged to be turned in to blueprint nodes.

Oh ok! I better understand now :smiley: This is why there’s a lot of people telling that the engine is a lot based around macros. Thanks a lot man for all those useful information :wink: It’s really intimidating to learn all those stuffs related to the engine, but thanks to you it’s a bit more easier!