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

u3r8eeie  于 2022-11-19  发布在  其他
关注(0)|答案(1)|浏览(345)

我在FCraftingRecipie结构中声明变量时遇到问题。因为第19行引发错误无法识别的类型“FMasterItem”-类型必须是UCLASS、USTRUCT或UENUM -MasterItem. h-第19行
Master项目需要存储FCraftingRecipie数组,因为这是所需项目和数量的列表。
以下是主项目头文件的副本

  1. #pragma once
  2. #include "CoreMinimal.h"
  3. #include "GameFramework/Actor.h"
  4. #include "Engine/DataTable.h"
  5. #include "MasterItem.generated.h"
  6. USTRUCT(BlueprintType)
  7. struct FCraftingRecipie : public FTableRowBase
  8. {
  9. GENERATED_BODY()
  10. public:
  11. FCraftingRecipie();
  12. UPROPERTY(EditAnywhere, BlueprintReadWrite)
  13. FMasterItem itemClass;
  14. UPROPERTY(EditAnywhere, BlueprintReadWrite)
  15. int amount;
  16. };
  17. USTRUCT(BlueprintType)
  18. struct FMasterItem : public FTableRowBase
  19. {
  20. GENERATED_BODY()
  21. public:
  22. FMasterItem();
  23. UPROPERTY(EditAnywhere, BlueprintReadWrite)
  24. FName itemID;
  25. UPROPERTY(EditAnywhere, BlueprintReadWrite)
  26. FText name;
  27. UPROPERTY(EditAnywhere, BlueprintReadWrite)
  28. FText description;
  29. UPROPERTY(EditAnywhere, BlueprintReadWrite)
  30. UTexture2D* itemIcon;
  31. UPROPERTY(EditAnywhere, BlueprintReadWrite)
  32. bool canBeUsed;
  33. UPROPERTY(EditAnywhere, BlueprintReadWrite)
  34. FText useText;
  35. UPROPERTY(EditAnywhere, BlueprintReadWrite)
  36. bool isStackable;
  37. UPROPERTY(EditAnywhere, BlueprintReadWrite)
  38. float itemWeight;
  39. UPROPERTY(EditAnywhere, BlueprintReadWrite)
  40. TArray<FCraftingRecipie> recipie;
  41. UPROPERTY(EditAnywhere, BlueprintReadWrite)
  42. float price;
  43. bool operator==(const FMasterItem& OtherItem) const
  44. {
  45. if (itemID == OtherItem.itemID)
  46. {
  47. return true;
  48. }
  49. return false;
  50. }
  51. };
7rfyedvj

7rfyedvj1#

你在FCraftingRecipie的第19行声明了一个FMasterItem字段(itemClass)。但是,你只能在同一个文件中声明FMasterItem。这在C++中不起作用,你需要在同一个文件中的其他地方引用它之前定义类(这就是为什么错误说类型无法识别)。
我建议把FCraftingRecipie声明移到FMasterItem下面。但是FMasterItem也引用了FCraftingRecipie。你所创建的是一个循环依赖,A需要知道B,但是B也需要知道A。这种情况可以通过使用引用/指针而不是值类型字段来解决。

相关问题