Hi,
So I’ve got yet another Epic and Unreal problem!
I’ve a class CombatAttributeSet that inherits from Unreal’s GAS AttributeSet.
I’ve edited and successfully compiled the file several times now.
However, now, out of the blue, it refuses to compile.
Just by adding a linejump → Fails compile
Manually removing the linejump → Fails compile
Ctrl-Z twice → Compiles again
The error is:
Severity | Code | Description | Project | File | Line | Suppression State |
---|---|---|---|---|---|---|
Error | C2027 | use of undefined type ‘UAbilitySystemComponent’ | TPSMPPG | W:\Projects\TPSMPPG_Project\TPSMPPG\Source\TPSMPPG\Public\GAS\CombatAttributeSet.h | 32, 41, 48 and 57 |
The troubling line is:
UPROPERTY(BlueprintReadOnly, Category = "Attributes", ReplicatedUsing = OnRep_Health)
FGameplayAttributeData Health;
THIS ONE ==>> ATTRIBUTE_ACCESSORS(UCombatAttributeSet, Health); <<== THIS ONE
UFUNCTION()
virtual void OnRep_Health(const FGameplayAttributeData& old);
Note: The error happens 4 times because I have 4 values: Health, Mana, HealthRegen and ManaRegen. For simplicity I’ve removed them from the code snippets below.
I’ve tried:
Deleting the repertories: .vs, Build, Intermediate, Saved and the vs solution.
Re-Generate the VS solution and rebuild but still doesnt work.
Maybe useful:
FGameplayAttributeData has a forward declaration for UAbilitySystemComponent. This is unreal’s code, untampered.
Below is the code:
.h
#pragma once
#include "CoreMinimal.h"
#include "AttributeSet.h"
#include "GameplayEffectExtension.h"
#include "CombatAttributeSet.generated.h"
#define ATTRIBUTE_ACCESSORS(ClassName, PropertyName)\
GAMEPLAYATTRIBUTE_PROPERTY_GETTER(ClassName, PropertyName)\
GAMEPLAYATTRIBUTE_VALUE_GETTER(PropertyName)\
GAMEPLAYATTRIBUTE_VALUE_SETTER(PropertyName)\
GAMEPLAYATTRIBUTE_VALUE_INITTER(PropertyName)
/**
*
*/
UCLASS()
class TPSMPPG_API UCombatAttributeSet : public UAttributeSet
{
GENERATED_BODY()
public:
UCombatAttributeSet();
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
UPROPERTY(BlueprintReadOnly, Category = "Attributes", ReplicatedUsing = OnRep_Health)
FGameplayAttributeData Health;
ATTRIBUTE_ACCESSORS(UCombatAttributeSet, Health);
UFUNCTION()
virtual void OnRep_Health(const FGameplayAttributeData& old);
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Attributes", meta = (ClampMin = "0"))
float MaxHealth;
protected:
virtual void PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue) override;
virtual bool PreGameplayEffectExecute(FGameplayEffectModCallbackData& data) override;
virtual void PostGameplayEffectExecute(const FGameplayEffectModCallbackData& data) override;
private:
};
.cpp
#include "GAS/CombatAttributeSet.h"
#include "Print.h"
#include "AttributeSet.h"
#include "AbilitySystemComponent.h"
#include "Net/UnrealNetwork.h"
UCombatAttributeSet::UCombatAttributeSet()
{
MaxHealth = 100;
}
void UCombatAttributeSet::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME_CONDITION_NOTIFY(UCombatAttributeSet, Health, COND_None, REPNOTIFY_Always);
}
void UCombatAttributeSet::OnRep_Health(const FGameplayAttributeData& old)
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UCombatAttributeSet, Health, old);
}
void UCombatAttributeSet::PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue)
{
Super::PreAttributeChange(Attribute, NewValue);
if (Attribute == GetHealthAttribute())
{
NewValue = FMath::Clamp<float>(NewValue, 0, MaxHealth);
}
}
bool UCombatAttributeSet::PreGameplayEffectExecute(FGameplayEffectModCallbackData& data)
{
return Super::PreGameplayEffectExecute(data);
}
void UCombatAttributeSet::PostGameplayEffectExecute(const FGameplayEffectModCallbackData& data)
{
Super::PostGameplayEffectExecute(data);
if (data.EvaluatedData.Attribute == GetHealthAttribute()) {
SetHealth(FMath::Clamp<float>(GetHealth(), 0.0f, MaxHealth));
}
}
Any help much apreciated, thanks