I have a GE for an Block attribute and I want to be able to add block chance based on different conditions. E.g. block physical attack chance, block elemental spell chance, …
I got different tags such as Damage.Physical, Damage.Elemental, Ability.Attack, Ability.Spell. Instead of creating 4 GEs for each combination I wanted to use these tags as SourceTags for a single DE_Block and add the tags programmatically in cpp.
I tried to add a function similar to this:
bool UCustom_BlueprintLibrary::AddTagsToGameplayEffectModifier(
const UGameplayEffect* GameplayEffect,
const FGameplayTagContainer& SourceTags,
const FGameplayTagContainer& TargetTags
) {
if (GameplayEffect->Modifiers.IsEmpty()) return false;
auto Modifier = GameplayEffect->Modifiers[0];
if (SourceTags.IsValid())
{
Modifier.SourceTags.RequireTags.AppendTags(SourceTags);
}
if (TargetTags.IsValid())
{
Modifier.TargetTags.RequireTags.AppendTags(TargetTags);
}
return true;
}
However, no matter what I try, it seems it is not possible to modify the existing modifiers. Any Idea how I can achieve this behavior without defining GEs for every combination?
Edit: another approach I tried
bool UCustom_BlueprintLibrary::AddTagToGameplayEffectModifier(
const UGameplayEffect* GameplayEffect,
const FGameplayAttribute& Attribute,
const FGameplayTag& SourceTag,
const FGameplayTag& TargetTag
) {
if (GameplayEffect->Modifiers.IsEmpty()) return false;
const auto Modifier = GameplayEffect->Modifiers.FindByPredicate(
[&](const FGameplayModifierInfo& Item)
{
return Item.Attribute == Attribute;
}
);
if (Modifier == nullptr) return false;
if (SourceTag.IsValid())
{
auto Tags = Modifier->SourceTags.RequireTags;
Tags.AddTag(SourceTag);
}
if (TargetTag.IsValid())
{
auto Tags = Modifier->TargetTags.RequireTags;
Tags.AddTag(TargetTag);
}
return true;
}