I would like to be able to dynamically control the ChanceToApply on a UGameplayEffect. The ‘ChanceToApply’ variable works, but I’m not sure if it would give me the flexibility I’d like.
Currently working on an RPG game in which I would like the ChanceToApply be based on a dice roll and then be able to add this roll to a Combat Log before attempting to apply the effect.
So far I’ve set up the GamePlayAbility system such that the GameplayAbility is triggering, the GameplayEffect is firing, and the following UGameplayEffectExecutionCalculation is running… but the GameplayEffect still applies every time! I set the spec to a 0% hit chance in the Execution. What have I done incorrectly here?
#include "BaseToHitCalculation.h"
#include "Math/UnrealMathUtility.h"
#include "GameplayEffect.h"
void UBaseToHitCalculation::Execute_Implementation(const FGameplayEffectCustomExecutionParameters& ExecutionParams, FGameplayEffectCustomExecutionOutput& OutExecutionOutput) const {
int32 d20Roll = FMath::RandRange(1, 20);
UE_LOG(LogTemp, Error, TEXT("D20 roll: %d"), d20Roll);
FGameplayEffectSpec Spec = ExecutionParams.GetOwningSpec();
UE_LOG(LogTemp, Error, TEXT("SETTING HIT CHANGE TO MISS"));
Spec.ChanceToApplyToTarget = 0.0f;
}