UE4 C ++无法识别的类型'FMasterItem'-类型必须是UCLASS,USTRUCT或UENUM

问题描述 投票:0回答:1

我在FCraftingRecipie结构中声明变量时遇到问题。当第19行引发错误无法识别的类型'FMasterItem'-类型必须是UCLASS,USTRUCT或UENUM-MasterItem.h-第19行

主项目需要存储FCraftingRecipie的数组,因为这是所需项目和金额的列表。

这里是MasterItem头文件的副本

#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;
    }
};
c++ structure unreal-engine4
1个回答
0
投票

您在FCraftingRecipie中声明了FMasterItem字段(itemClass)第19行。但是,之后只能在同一文件中声明FMasterItem。这在C ++中不起作用,您需要先定义该类,然后才能在同一文件的其他位置引用它(这就是为什么该错误表明无法识别类型的原因)。

我建议将FCraftingRecipie声明移到FMasterItem下。但是,FMasterItem也引用FCraftingRecipie。您创建的是循环依赖关系,即A需要了解B,而B需要了解A的情况。可以通过使用引用/指针而不是值类型字段来解决这类礼仪问题。

© www.soinside.com 2019 - 2024. All rights reserved.