Getting error

I tried to add to array a variable from datatable, which was declared using TSubclassOf.
And i got this error


this is cpp file

AMainItem* Item = ItemDataTable[ArrayIndex]->FindRow(FName(FString::FromInt(IndexOfElement)), “”, false)->Item;

this is my struct in h file

USTRUCT(BlueprintType)
struct FRandomItemData : public FTableRowBase
{
GENERATED_BODY()

	UPROPERTY(EditAnywhere)
		TSubclassOf<AMainItem> Item;
	UPROPERTY(EditAnywhere)
		int32 Amount = 1;
	UPROPERTY(EditAnywhere)
		int32 Cost = 1;

};

A TSubclassOf is a type safe wrapper of UClass* which contains reflected metadata about some type. It is not something that will exist in the game world.

Your code is trying to do this

TSubclassOf<AMainItem> ItemClass;
AMainItem* Item = ItemClass

Which doesn’t make sense, a UClass* can’t be converted to the type that it is a reflection of.

Privacy & Terms