In this lesson, you will learn how to define specialized C++ structures that Unreal Engine can automatically parse into Data Tables.
The Role of FTableRowBase
While you already know how to define a USTRUCT, simply creating one isn't enough to make it compatible with the Data Table system. To bridge the gap, your struct must inherit from FTableRowBase. This base struct provides the necessary metadata for Unreal’s editor tools to recognize your data as a valid table row.
When you inherit from FTableRowBase, the engine's internal reflection system treats your struct as a record that can be stored, filtered, and accessed via the Data Table asset type.
Defining Your Row Struct
To set this up, define your struct in a header file, mark it with USTRUCT(BlueprintType), and ensure it inherits from FTableRowBase. Each variable you want to be editable in the table must be marked with UPROPERTY(EditAnywhere).
#include "Engine/DataTable.h"
#include "MyDataStruct.generated.h"
USTRUCT(BlueprintType)
struct FWeaponData : public FTableRowBase
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, BlueprintReadOnly)
FName WeaponName;
UPROPERTY(EditAnywhere, BlueprintReadOnly)
float DamageValue;
UPROPERTY(EditAnywhere, BlueprintReadOnly)
TSubclassOf<AActor> WeaponClass;
};
Why This Matters
By following this pattern, you gain several immediate benefits:
- Editor Integration: You can create a new Data Table asset in the Content Browser, select
FWeaponDataas the Row Structure, and the editor will automatically build the interface for you. - Type Safety: You move your hardcoded "magic numbers" (like weapon damage or item names) out of C++ and into a structured format that designers can edit without recompiling code.
- Optimized Lookups: The engine provides specialized functions like
FindRow<FWeaponData>to retrieve this data by name efficiently during runtime.
By using FTableRowBase, you transform a simple data container into a powerful, data-driven architecture that keeps your game logic separate from your game content.
Key Takeaway: Inheriting from FTableRowBase is the mandatory step to make your custom UStructs compatible with Unreal’s Data Table system, allowing for flexible, data-driven gameplay design.