Hi,
I’m trying to implement a simple periodic health regen gameplay effect.
My set-up is the following:
-
HealthAttributeSet
has 3 properties:Health
,HealthMax
andHealthRegenRate
-
HealthComponent(ActorComponent)
addsHealthAttributeSet
to its owner’sAbilitySystemComponent
onBeginPlay
, and applies a gameplay effect set in the editor. -
The set gameplay effect has one modifier on
Health
, based onAttributeBased
HealthRegenRate
.
Here is my HealthComponent
code:
void HealthComponent::BeingPlay() {
...
auto HealthAttributeSet = NewObject<UHealthAttributeSet>(AbilitySystemComponent);
HealthAttributeSet->InitHealth(Health);
HealthAttributeSet->InitHealthMax(HealthMax);
HealthAttributeSet->InitHealthRegenRate(HealthRegenRate);
AbilitySystemComponent->AddAttributeSetSubobject(HealthAttributeSet);
if (HealthEffect) {
FGameplayEffectContextHandle ContextHandle(
UAbilitySystemGlobals::Get().AllocGameplayEffectContext());
FGameplayEffectSpec Spec(HealthEffect.GetDefaultObject(), ContextHandle);
AbilitySystemComponent->ApplyGameplayEffectSpecToSelf(Spec);
}
}
Also, MyCharacter code:
void AMyCharacter::PossessedBy(AController* NewController)
{
Super::PossessedBy(NewController);
AbilitySystemComponent->InitAbilityActorInfo(NewController, this);
}
The warning I get at every periodic event, and the gameplay effect doesn’t affect the character at all, as the gameplay effect fell back to 0:
Warning: Modifier on spec: Default__GEHealth_C was asked to CalculateMagnitude and failed, falling back to 0.
Sometimes, I don’t even see the warning, nor other simpler gameplay effects (i.e. instant damage) silently fail to apply to the target.
Thanks for reading and offering your help.