I am trying to get a custom execution class to work following the GasDocumentation project example. I have a gameplay effect like this:
- Every time I apply the effect the modifier portion is applied (I see MaxHealth increase by 1) but the execution is never triggered.
I thought all I should need to do is override the Execute_Implementation like so
#include "CoreMinimal.h"
#include "GameplayEffectExecutionCalculation.h"
#include "GEC_Vitality.generated.h"
UCLASS()
class TEMP_API UGEC_Vitality : public UGameplayEffectExecutionCalculation
{
GENERATED_BODY()
public:
UGEC_Vitality();
virtual void Execute_Implementation(const FGameplayEffectCustomExecutionParameters& ExecutionParams, OUT FGameplayEffectCustomExecutionOutput& OutExecutionOutput) const override;
};
I have put breakpoints at the very top of the Execute_Implementation function and it is never called. The constructor for the class is called when the engine initializes. What do I need to do to make it so that Execute_Implementation is actually called?
#include "GEC_Vitality.h"
#include "FighterAttributeSet.h"
#include "Fighter_ASC.h"
struct FHealthStats {
DECLARE_ATTRIBUTE_CAPTUREDEF(MaxHealth);
FHealthStats()
{
DEFINE_ATTRIBUTE_CAPTUREDEF(UFighterAttributeSet, MaxHealth, Target, false);
}
};
static const FHealthStats& HealthStats()
{
static FHealthStats hStats;
return hStats;
}
UGEC_Vitality::UGEC_Vitality()
{
RelevantAttributesToCapture.Add(HealthStats().MaxHealthDef);
}
void UGEC_Vitality::Execute_Implementation(const FGameplayEffectCustomExecutionParameters& ExecutionParams, OUT FGameplayEffectCustomExecutionOutput& OutExecutionOutput) const
{
UAbilitySystemComponent* TargetAbilitySystemComponent = ExecutionParams.GetTargetAbilitySystemComponent();
UAbilitySystemComponent* SourceAbilitySystemComponent = ExecutionParams.GetSourceAbilitySystemComponent();
AActor* SourceActor = SourceAbilitySystemComponent ? SourceAbilitySystemComponent->GetAvatarActor() : nullptr;
AActor* TargetActor = TargetAbilitySystemComponent ? TargetAbilitySystemComponent->GetAvatarActor() : nullptr;
const FGameplayEffectSpec& Spec = ExecutionParams.GetOwningSpec();
// Gather the tags from the source and target as that can affect which buffs should be used
const FGameplayTagContainer* SourceTags = Spec.CapturedSourceTags.GetAggregatedTags();
const FGameplayTagContainer* TargetTags = Spec.CapturedTargetTags.GetAggregatedTags();
FAggregatorEvaluateParameters EvaluationParameters;
EvaluationParameters.SourceTags = SourceTags;
EvaluationParameters.TargetTags = TargetTags;
float hGain = Spec.GetLevel() + 2;
if (GEngine)
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, FString::Printf(TEXT("Level %f"), Spec.GetLevel()));
OutExecutionOutput.AddOutputModifier(FGameplayModifierEvaluatedData(HealthStats().MaxHealthProperty, EGameplayModOp::Additive, hGain));
}
