我在FCraftingRecipie结构中声明变量时遇到问题。因为第19行引发错误无法识别的类型“FMasterItem”-类型必须是UCLASS、USTRUCT或UENUM -MasterItem. h-第19行
Master项目需要存储FCraftingRecipie数组,因为这是所需项目和数量的列表。
以下是主项目头文件的副本
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Engine/DataTable.h"
#include "MasterItem.generated.h"
USTRUCT(BlueprintType)
struct FCraftingRecipie : public FTableRowBase
{
GENERATED_BODY()
public:
FCraftingRecipie();
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FMasterItem itemClass;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int amount;
};
USTRUCT(BlueprintType)
struct FMasterItem : public FTableRowBase
{
GENERATED_BODY()
public:
FMasterItem();
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FName itemID;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FText name;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FText description;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UTexture2D* itemIcon;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool canBeUsed;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FText useText;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool isStackable;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float itemWeight;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<FCraftingRecipie> recipie;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float price;
bool operator==(const FMasterItem& OtherItem) const
{
if (itemID == OtherItem.itemID)
{
return true;
}
return false;
}
};
1条答案
按热度按时间7rfyedvj1#
你在FCraftingRecipie的第19行声明了一个FMasterItem字段(itemClass)。但是,你只能在同一个文件中声明FMasterItem。这在C++中不起作用,你需要在同一个文件中的其他地方引用它之前定义类(这就是为什么错误说类型无法识别)。
我建议把FCraftingRecipie声明移到FMasterItem下面。但是FMasterItem也引用了FCraftingRecipie。你所创建的是一个循环依赖,A需要知道B,但是B也需要知道A。这种情况可以通过使用引用/指针而不是值类型字段来解决。