Data Tables and Structures?

I’m trying to create a c++ data table using a c++ struct(USTRUCT inheriting from FTableRowBase) and wanted to know if and how I could implement the data table(in c++) using the struct I created in the same class. This is for an inventory system.

DataTable.h

USTRUCT()
struct ItemStructure : public FTableRowBase
{
	GENERATED_BODY()
		

	UPROPERTY(EditAnywhere, BlueprintReadOnly)
		FText DisplayName;
	
	UPROPERTY(EditAnywhere, BlueprintReadOnly)
		FText Description;

	UPROPERTY(EditAnywhere, BlueprintReadOnly)
		UTexture2D Thumbnail;

	UPROPERTY(EditAnywhere, BlueprintReadOnly)
		UStaticMesh Mesh;

	UPROPERTY(EditAnywhere, BlueprintReadOnly)
		bool Stackable;
}

UCLASS()
class CPP_TEST_B_API UItemDataTable : public UDataTable
{
	GENERATED_BODY()
	

};

And thanks in advance!

2 Likes

You don’t create DataTables in C++ because they are assets. DataTables are essentially just wrapper classes for TMap<FName, FMyStruct> - but store raw data and reinterpret it into the correct type.

You just need to create a new Data Table in the editor, and choose your struct as the type in the modal window that pops up. If you want to use that table in C++, you’ll need to store a reference to it somewhere.

There’s also a convenient FDataTableRowHandle type if you want to store a reference to a specific row of a data table, and UPROPERTY markup to limit the options to a given Row Type.

3 Likes