C++ ';装备项目';can';不可编译:父类';项目';有错误:虚幻引擎4.26 c++;
我有一个错误:“EquipableItem”无法编译:父类“Item”有错误。我试图排除EquipableItem类并重新生成项目,以隔离Item类中的错误,并在编译器中显示它们。我已经检查了所有循环依赖项并修复了它们。但仍然存在这个错误。你能告诉我下一步我能做什么吗 有一个编译器输出:C++ ';装备项目';can';不可编译:父类';项目';有错误:虚幻引擎4.26 c++;,c++,parent,unreal-engine4,C++,Parent,Unreal Engine4,我有一个错误:“EquipableItem”无法编译:父类“Item”有错误。我试图排除EquipableItem类并重新生成项目,以隔离Item类中的错误,并在编译器中显示它们。我已经检查了所有循环依赖项并修复了它们。但仍然存在这个错误。你能告诉我下一步我能做什么吗 有一个编译器输出: 1>------ Build started: Project: SurvivalGame, Configuration: Development_Editor x64 ------ 1>Parsi
1>------ Build started: Project: SurvivalGame, Configuration: Development_Editor x64 ------
1>Parsing headers for SurvivalGameEditor
1> Running UnrealHeaderTool "D:\OneDrive\Dokumenty\All\UnrealEngine\Tutorials\SurvivalGame\SurvivalGame.uproject" "D:\OneDrive\Dokumenty\All\UnrealEngine\Tutorials\SurvivalGame\Intermediate\Build\Win64\SurvivalGameEditor\Development\SurvivalGameEditor.uhtmanifest" -LogCmds="loginit warning, logexit warning, logdatabase error" -Unattended -WarningsAsErrors -abslog="C:\Users\xondr\AppData\Local\UnrealBuildTool\Log_UHT.txt" -installed
1>D:/OneDrive/Dokumenty/All/UnrealEngine/Tutorials/SurvivalGame/Source/SurvivalGame/Items/EquipableItem.h(32): error : 'EquipableItem' can't be compiled: Parent class 'Item' has errors
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.MakeFile.Targets(46,5): error MSB3073: The command "C:\Windows\System32\chcp.com 65001 >NUL
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.MakeFile.Targets(46,5): error MSB3073: "C:\Program Files\Epic Games\UE_4.26\Engine\Build\BatchFiles\Build.bat" SurvivalGameEditor Win64 Development -Project="D:\OneDrive\Dokumenty\All\UnrealEngine\Tutorials\SurvivalGame\SurvivalGame.uproject" -WaitMutex -FromMsBuild" exited with code 6.
1>Done building project "SurvivalGame.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
项目.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "Player/SurivalCharacter.h"
//#include "Inventory/InventoryComponent.h"
#include "Net/UnrealNetwork.h"
#include "Item.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnItemModified);
UENUM(BlueprintType)
enum class EItemRarity : uint8
{
IR_Common UMETA(DisplayName = "Common"),
IR_Uncommon UMETA(DisplayName = "Uncommon"),
IR_Rare UMETA(DisplayName = "Rare"),
IR_VeryRare UMETA(DisplayName = "Very Rare"),
IR_Legendary UMETA(DisplayName = "Legendary")
};
/**
*
*/
UCLASS(Blueprintable, EditInlineNew, DefaultToInstanced)
class SURVIVALGAME_API UItem : public UObject
{
GENERATED_BODY()
protected:
virtual void GetLifetimeReplicatedProps(TArray<class FLifetimeProperty> & OutLifetimeProps) const override;
virtual bool IsSupportedForNetworking() const override;
#if WITH_EDITOR
virtual void PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) override;
#endif
public:
UItem();
//The mesh to display for this items pickup
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item")
class UStaticMesh* PickupMesh;
//The thumbnail for this item
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Item")
class UTexture2D* Thumbnail;
//The display name for this item in the inventory
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item")
FText ItemDisplayName;
//An optional description for the item
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item", meta = (MultiLine = true))
FText ItemDescription;
//The text for using the item. (Equip, Eat, etc)
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item")
FText UseActionText;
//The rarity of the item
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item")
EItemRarity Rarity;
//The weight of the item
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item", meta = (ClampMin = 0.0))
float Weight;
//Whether or not this item can be stacked
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item")
bool bStackable;
//The maximum size that a stack of items can be
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item", meta = (ClampMin = 2, EditCondition = bStackable))
int32 MaxStackSize;
//The tooltip in the inventory for this item
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item")
TSubclassOf<class UItemTooltip> ItemTooltip;
//The amount of the item
UPROPERTY(ReplicatedUsing = OnRep_Quantity, EditAnywhere, Category = "Item", meta = (UIMin = 1, EditCondition = bStackable))
int32 Quantity;
//The inventory that owns this item
UPROPERTY()
class UInventoryComponent* OwningInventory;
//Used to efficiently replicate inventory items
UPROPERTY()
int32 RepKey;
UPROPERTY(BlueprintAssignable)
FOnItemModified OnItemModified;
UFUNCTION()
void OnRep_Quantity();
UFUNCTION(BlueprintCallable, Category = "Item")
void SetQuantity(const int32 NewQuantity);
UFUNCTION(BlueprintPure, Category = "Item")
FORCEINLINE int32 GetQuantity() const { return Quantity; }
UFUNCTION(BlueprintCallable, Category = "Item")
FORCEINLINE float GetStackWeight() const { return Quantity * Weight; }
UFUNCTION(BlueprintPure, Category = "Item")
virtual bool ShouldShowInInventory() const;
virtual void Use(class ASurivalCharacter* Character);
virtual void AddedToInventory(class UInventoryComponent* Inventory);
//Mark the object as needing replication. We must call this internally after modifying any replicated properties
void MarkDirtyForReplication();
};
//在项目设置的说明页中填写版权声明。
#布拉格语一次
#包括“coremilimal.h”
#包括“UObject/NoExportTypes.h”
#包括“Player/SurivalCharacter.h”
//#包括“库存/库存组件.h”
#包括“Net/UnrealNetwork.h”
#包括“Item.generated.h”
声明\u动态\u多播\u委托(FOnItemModified);
UENUM(蓝图类型)
枚举类EItemRarity:uint8
{
IR_Common UMETA(DisplayName=“Common”),
IR_unformal UMETA(DisplayName=“unformal”),
IR_稀有梅塔(DisplayName=“稀有”),
IR_VeryRare UMETA(DisplayName=“非常罕见”),
IR_Legendary UMETA(DisplayName=“Legendary”)
};
/**
*
*/
UCLASS(可蓝图打印、EditInlineNew、DefaultToInstalled)
类SURVIVALGAME\u API UItem:公共UObject
{
生成的_BODY()
受保护的:
虚拟无效GetLifetimeReplicatedProps(TArray和OutlineFeTimeProps)常量覆盖;
虚拟布尔IsSupportedForNetworking()常量覆盖;
#如果使用编辑器
虚拟无效PostEditChangeProperty(struct FPropertyChangedEvent和PropertyChangedEvent)重写;
#恩迪夫
公众:
UItem();
//要为此拾取项目显示的网格
Upperty(编辑默认值,BlueprintReadWrite,Category=“Item”)
类别UStaticMesh*PickupMesh;
//此项目的缩略图
Upperty(仅限EditDefaultsOnly、BlueprintReadOnly、Category=“Item”)
类UTexture2D*缩略图;
//此项目在库存中的显示名称
Upperty(编辑默认值,BlueprintReadWrite,Category=“Item”)
FText ItemDisplayName;
//项目的可选描述
upperty(EditDefaultsOnly,BlueprintReadWrite,Category=“Item”,meta=(MultiLine=true))
FText项目描述;
//使用物品的文字。(装备、进食等)
Upperty(编辑默认值,BlueprintReadWrite,Category=“Item”)
FText使用actiontext;
//珍品
Upperty(编辑默认值,BlueprintReadWrite,Category=“Item”)
稀有性;
//物品的重量
upperty(编辑默认值,BlueprintReadWrite,Category=“Item”,meta=(ClampMin=0.0))
浮重;
//此项是否可以堆叠
Upperty(编辑默认值,BlueprintReadWrite,Category=“Item”)
boolbstackable;
//一个项目堆栈可以达到的最大大小
upperty(EditDefaultsOnly,BlueprintReadWrite,Category=“Item”,meta=(ClampMin=2,EditCondition=bStackable))
int32 MaxStackSize;
//此项目清单中的工具提示
Upperty(编辑默认值,BlueprintReadWrite,Category=“Item”)
TsubClassofItemToolTip;
//项目的金额
upperty(ReplicatedUsing=OnRep_数量,EditAnywhere,Category=“Item”,meta=(UIMin=1,EditCondition=bStackable))
int32数量;
//拥有此项目的库存
连根拔起
类别UInventoryComponent*OwningInventory;
//用于高效地复制库存项目
连根拔起
英特基;
Upperty(蓝图可转让)
FONITEM改性或非改性;
UFUNCTION()
无效的重复数量();
UFUNCTION(BlueprintCallable,Category=“Item”)
无效设置数量(const int32 NewQuantity);
UFUNCTION(BlueprintPure,Category=“Item”)
FORCEINLINE int32 GetQuantity()常量{返回数量;}
UFUNCTION(BlueprintCallable,Category=“Item”)
FORCEINLINE float GetStackWeight()常量{返回数量*重量;}
UFUNCTION(BlueprintPure,Category=“Item”)
虚拟布尔值应显示InInventory()常量;
虚空使用(类ASurivalCharacter*字符);
添加到存货中的虚拟作废(UIN存货类部件*存货);
//将该对象标记为需要复制。我们必须在修改任何已复制属性后在内部调用它
void MarkDirtyForReplication();
};
项目1.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "Item.h"
#define LOCTEXT_NAMESPACE "Item"
void UItem::GetLifetimeReplicatedProps(TArray<class FLifetimeProperty> & OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(UItem, Quantity);
}
bool UItem::IsSupportedForNetworking() const
{
return true;
}
#if WITH_EDITOR
void UItem::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
Super::PostEditChangeProperty(PropertyChangedEvent);
FName ChangedPropertyName = PropertyChangedEvent.Property ? PropertyChangedEvent.Property->GetFName() : NAME_None;
//UPROPERTY clamping doesn't support using a variable to clamp so we do in here instead
if (ChangedPropertyName == GET_MEMBER_NAME_CHECKED(UItem, Quantity))
{
Quantity = FMath::Clamp(Quantity, 1, bStackable ? MaxStackSize : 1);
}
}
#endif
UItem::UItem()
{
ItemDisplayName = LOCTEXT("ItemName", "Item");
UseActionText = LOCTEXT("ItemUseActionText", "Use");
Weight = 0.f;
bStackable = true;
Quantity = 1;
MaxStackSize = 2;
RepKey = 0;
}
void UItem::OnRep_Quantity()
{
OnItemModified.Broadcast();
}
void UItem::SetQuantity(const int32 NewQuantity)
{
if (NewQuantity != Quantity)
{
Quantity = FMath::Clamp(NewQuantity, 0,bStackable ? MaxStackSize : 1);
MarkDirtyForReplication();
}
}
bool UItem::ShouldShowInInventory() const
{
return true;
}
void UItem::Use(ASurivalCharacter* Character)
{
}
void UItem::AddedToInventory(UInventoryComponent* Inventory)
{
}
void UItem::MarkDirtyForReplication()
{
//Mark this object for replication
++RepKey;
//Mark the array for replication
if (OwningInventory)
{
++OwningInventory->ReplicatedItemsKey;
}
}
#undef LOCTEXT_NAMESPACE
//在项目设置的说明页中填写版权声明。
#包括“项目h”
#定义LOCTEXT_命名空间“项”
void UItem::GetLifetimeReplicatedProps(TArray和OutlineFeTimeProps)常量
{
Super::GetLifetimeReplicatedProps(OutlineFeTimeProps);
DOREPILIFE(UItem,数量);
}
bool UItem::IsSupportedForNetworking()常量
{
返回true;
}
#如果使用编辑器
void UItem::PostEditChangeProperty(FPropertyChangedEvent和PropertyChangedEvent)
{
Super::PostEditChangeProperty(PropertyChangedEvent);
FName ChangedPropertyName=PropertyChangedEvent.Property?PropertyChangedEvent.Property->GetFName():NAME\u None;
//Upperty钳制不支持使用变量来钳制,所以我们在这里改为使用变量
if(ChangedPropertyName==GET_MEMBER_NAME_CHECKED(UItem,Quantity))
{
数量=FMath::Clamp(数量,1,b可堆叠?MaxStackSize:1);
}
}
#恩迪夫
UItem::UItem()
{
ItemDisplayName=LOCTEXT(“ItemName”、“Item”);
UseActionText=LOCTEXT(“项目UseActionText”,“使用”);
重量=0.f;
bStackable=true;
数量=1;
MaxStackSize=2;
RepKey=0;
}
void UItem::OnRep_数量()
{
OnItemModified.Broadcast();
}
void UItem::SetQuantity(const int32 NewQuantity)
{
如果(新数量!=数量)
{
数量=FMath::Clamp(NewQuantity,0,bStackable?MaxStackSize:1);
MarkDirtyForReplication();
}
}
bool UItem::ShouldShowInInventory()常量
{
返回true;
}
void UItem::Use(ASurivalCharacter*字符)
{
}
作废UItem::添加到库存(UINVENTORY组件*库存)
{
}
void UItem::MarkDirtyForReplication(
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Items/Item.h"
#include "EquipableItem.generated.h"
//All the slots that gear can be equipped to.
UENUM(BlueprintType)
enum class EEquippableSlot : uint8
{
EIS_Head UMETA(DisplayName = "Head"),
EIS_Helmet UMETA(DisplayName = "Helmet"),
EIS_Chest UMETA(DisplayName = "Chest"),
EIS_Vest UMETA(DisplayName = "Vest"),
EIS_Legs UMETA(DisplayName = "Legs"),
EIS_Feet UMETA(DisplayName = "Feet"),
EIS_Hands UMETA(DisplayName = "Hands"),
EIS_Backpack UMETA(DisplayName = "Backpack"),
EIS_PrimaryWeapon UMETA(DisplayName = "PrimaryWeapon"),
EIS_Throwable UMETA(DisplayName = "Throwable Item")
};
/**
*
*/
UCLASS(Abstract, NotBlueprintable)
class SURVIVALGAME_API UEquipableItem : public UItem /*: public UObject*/
{
GENERATED_BODY()
public:
UEquipableItem();
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Equippables")
EEquippableSlot Slot;
virtual void GetLifetimeReplicatedProps(TArray<class FLifetimeProperty>& OutLifetimeProps) const override;
virtual void Use(class ASurivalCharacter* Character) override;
UFUNCTION(BlueprintCallable, Category = "Equippables")
virtual bool Equip(class ASurivalCharacter* Character);
UFUNCTION(BlueprintCallable, Category = "Equippables")
virtual bool UnEquip(class ASurivalCharacter* Character);
virtual bool ShouldShowInInventory() const override;
UFUNCTION(BlueprintPure, Category = "Equippables")
bool IsEquipped() { return bEquipped; };
//Call this on the server to equip the item
void SetEquipped(bool bNewEquipped);
protected:
UPROPERTY(ReplicatedUsing = EquipStatusChanged)
bool bEquipped;
UFUNCTION()
void EquipStatusChanged();
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "Items/EquipableItem.h"
//#include "EquipableItem.h"
//#include "Player/SurivalCharacter.h"
//#include "Net/UnrealNetwork.h"
//#include "Inventory/InventoryComponent.h"
#define LOCTEXT_NAMESPACE "EquippableItem"
UEquipableItem::UEquipableItem()
{
bStackable = false;
bEquipped = false;
UseActionText = LOCTEXT("ItemUseActionText", "Equip");
}
void UEquipableItem::GetLifetimeReplicatedProps(TArray<class FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(UEquipableItem, bEquipped);
}
void UEquipableItem::Use(ASurivalCharacter* Character)
{
if (Character && Character->HasAuthority())
{
if (Character->GetEquippedItems().Contains(Slot) && !bEquipped)
{
UEquipableItem* AlreadyEquippedItem = *Character->GetEquippedItems().Find(Slot);
AlreadyEquippedItem->SetEquipped(false);
}
SetEquipped(!IsEquipped());
}
}
bool UEquipableItem::Equip(ASurivalCharacter* Character)
{
if (Character)
{
return Character->EquipItem(this);
}
return false;
}
bool UEquipableItem::UnEquip(ASurivalCharacter* Character)
{
if (Character)
{
return Character->UnEquipItem(this);
}
return false;
}
bool UEquipableItem::ShouldShowInInventory() const
{
return !bEquipped;
}
void UEquipableItem::SetEquipped(bool bNewEquipped)
{
bEquipped = bNewEquipped;
EquipStatusChanged();
MarkDirtyForReplication();
}
void UEquipableItem::EquipStatusChanged()
{
if (ASurivalCharacter* Character = Cast<ASurivalCharacter>(GetOuter()))
{
if (bEquipped)
{
Equip(Character);
}
else
{
UnEquip(Character);
}
}
//Tell UI to update
OnItemModified.Broadcast();
}
#undef LOCTEXT_NAMESPACE