'EquipableItem' 无法编译:父类 'Item' 有错误 Unreal Engine 4.26 c++

问题描述

我有这个错误:“EquipableItem”无法编译:父类“Item”有错误。我试图排除 EquipableItem 类并重新生成项目以隔离 Item 类中的错误并将它们显示在编译器中。我已经检查了所有循环依赖项并修复了它们。但是还是有这个错误。你能告诉我接下来我能做什么吗?

一个编译器输出

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,Category = "Item")
    FText ItemdisplayName;

    //An optional description for the item
    UPROPERTY(EditDefaultsOnly,Category = "Item",Meta = (MultiLine = true))
    FText ItemDescription;

    //The text for using the item. (Equip,Eat,etc)
    UPROPERTY(EditDefaultsOnly,Category = "Item")
    FText UseActionText;

    //The rarity of the item
    UPROPERTY(EditDefaultsOnly,Category = "Item")
    EItemRarity Rarity;

    //The weight of the item
    UPROPERTY(EditDefaultsOnly,Meta = (ClampMin = 0.0))
    float Weight;

    //Whether or not this item can be stacked
    UPROPERTY(EditDefaultsOnly,Category = "Item")
    bool bStackable;

    //The maximum size that a stack of items can be
    UPROPERTY(EditDefaultsOnly,Meta = (ClampMin = 2,EditCondition = bStackable))
    int32 MaxStackSize;

    //The tooltip in the inventory for this item
    UPROPERTY(EditDefaultsOnly,Category = "Item")
    TSubclassOf<class UItemTooltip> ItemTooltip;

    //The amount of the item
    UPROPERTY(ReplicatedUsing = OnRep_Quantity,EditAnywhere,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();
};

项目.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,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

EquipableItem.h

// 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,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();
};

EquipableItem.cpp

// 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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)