I have there this error: 'EquipableItem' can't be compiled: Parent class 'Item' has errors. I have tried to exclude EquipableItem class and regenarated the project to isolate errors in Item class and showed up them in the compiler. I've checked all circular dependencies and repaired them. But there is still this error. Could you advise me please what next can I do?
There is an compiler output:
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 ==========
Item.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();
};
Item.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
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, 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();
};
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