Download

[GAS] Condtional Gameplay Effect with level restrictions (2 extra lines of code?)

I’m looking to create a conditional GE that will only be applied if the level of the original GE is at level 2.

Currently something similar exist with the property ConitionalGameplayEffects. However, there is no level restriction on it.
Looking at the source code:

https://github.com/EpicGames/UnrealEngine/blob/4.24.1-release/Engine/Plugins/Runtime/GameplayAbilities/Source/GameplayAbilities/Private/GameplayEffect.cpp#L632
bool FConditionalGameplayEffect::CanApply(const FGameplayTagContainer& SourceTags, float SourceLevel) const
{
// Right now we’re just using the tags but in the future we may gate this by source level as well
return SourceTags.HasAll(RequiredSourceTags);
}

As you can see, there is even a comment in there. The only thing left is:

  1. Add 2 properties to FConditionalGameplayEffect, float MinLevel and float MaxLevel. Should be default initialized to -1 to be backward compatible.
  2. inside :CanApply(), replace the condition with this:
    return SourceTags.HasAll(RequiredSourceTags) && (MinLevel < 0 || MinLevel <= SourceLevel) && (MaxLevel < 0 || SourceLevel <= MaxLevel);

Also note I tried to create a class derived from UGameplayEffect and implement it for my project only, but there are too many non-virtual methods to achieve that.