Download

[GAS] Applying a Gameplay Effect Spec with Source/Target Tags Requirements in C++ inside Gameplay Ability Class

I’m trying to cast a gameplay effect on a character with a gameplay effect spec to use the tag requirements and manage the modifiers that will be used. But I’m confused because my test character has all the requirement tags, but the effect doesn’t apply and i’m going crazy trying to figure out where i’m failing.

void UGASGameplayAbility::ApplyEffectToSelf()
{
     for (const auto& _Effect : AbilityEffects)
     {
         GetCurrentAbilitySpec()->SetByCallerTagMagnitudes.Add(_Effect.Key, AbilityActiveTime);
         auto _SpecHandle = MakeOutgoingGameplayEffectSpec(GetCurrentAbilitySpecHandle(), GetCurrentActorInfo(), GetCurrentActivationInfo(), _Effect.Value.Get());
 
         if (_SpecHandle.IsValid())
         {
             ApplyAbilityTagsToGameplayEffectSpec(*_SpecHandle.Data.Get(), GetCurrentAbilitySpec());
             ApplyGameplayEffectSpecToOwner(GetCurrentAbilitySpecHandle(), GetCurrentActorInfo(), GetCurrentActivationInfo(), _SpecHandle);
         }
     }
}

I tried other ways to apply what I want, but I was unsuccessful. The tags are being applied correctly to Gameplay Spec, I checked using GetActorTags() and GetSpecTags(), but the effect is not applied. When removing requirement tags from modifiers in the Gameplay Effect, the effect is applied normally.

The same happens when changing the application and tags from Source to Target.

I’m taking ideas on how I can better visualize what might be happening or examples of how to apply the effect with requirements. :S

Modifiers with duration only check tag requirements once right when the effect is applied. Are you sure the dodge ability tags are added to your character before the effect is applied?

UGameplayAbility::PreActivate() is where tags are added with AddLooseGamplayTag(). Check and see if this is called before the effect.

Also, check that the tag you’re checking for requirement is added in the dodge ability’s Activation Owned Tags, and not in Ability Tags. I’m not sure if source/target requirement tag checks for tags in that container.

Yes, the call to the ApplyEffectToSelf() function comes after PreActivate(), when the skill is already active and I’m checking the requirements with ActivationOwnedTags, but they’re not activating yet. And this applies to all other abilities that apply a requirement tag effect. :confused:

I also checked the tags applied to the character’s AbilitySystemComponent and they are also being applied, as well as the SpecHandle that is used to apply the GameplayEffect.

Also, the ApplyGameplayEffectSpecToOwner() function returns a FActiveGameplayEffectHandle that has a function called WasSuccessfullyApplied() to check if it was properly applied, and it has returned true. :S