I have defined a struct that actually exists in the UE (Unreal Engine) editor, its representation is in the form of a file. And now I want to reference it in C++ code using a pointer.
To do this, I used the following definition in the header file:
USTRUCT(BlueprintType)
struct FItemStatRow
{
GENERATED_BODY()
};
UCLASS(Blueprintable, Category = "DataDriven")
class DATAASSET_API UMyDataFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
UMyDataFunctionLibrary();
static FItemStatRow* MyStructPtr;
}
I have written the following code in the source file:
FItemStatRow* UMyDataFunctionLibrary::MyStructPtr = nullptr;
UMyDataFunctionLibrary::UMyDataFunctionLibrary() {
static ConstructorHelpers::FObjectFinder<UClass> StructFinder(TEXT("UserDefinedStruct'/Game/DataTable/PrepareData/S_ItemStatRow.S_ItemStatRow'"));
if (StructFinder.Succeeded()) {
UClass* StructClass = StructFinder.Object;
/*if (StructClass) {
MyStructPtr = Cast<FItemStatRow>(StructClass->GetDefaultObject());
}*/
}
}
The commented-out portion that I have is unable to compile, and I’m not sure what the issue is or how to fix it.
The error message specifically states that “StaticClass” is not a member of “FItemStatRow”.