Sharing: Apply Additional Effects (V2). Thoughts are welcome

Code link: UE5 - Apply Additional Effects (V2)

tl&dr: created a new UGameplayEffectComponent, similar to the existing Apply Additional Effects, but with enhancements. Including:

  1. Will create the effect on another target, based on boolean (Uses a custom effect context to extract that actor)
  2. Has a map of ModifierIndex → Tag, to set a tag in SetByCaller of the new effect, with the “Leftover” of an attribute.

“Long” story - why do I even need it?

I was looking on how to implement a “Mana Siphon” ability; where the player siphon mana from the target. Hence target gets -Mana, Player gets +Mana.

I started by having 2 abilities running at the same time: but it wasn’t syncing, and I sometimes ended up with more Mana than what was drained (one effect stopped before the other).

Using this new component and approach, the flow is:

  1. Ability will create a “Drain” effect on the target.
  2. “Drain” effect will add to “Drain” attribute, which will reduce mana. Any mana not drained are kept in theattribute. e.g. Actor has 25 mana, Drain wants to take away 30 mana - Drain attribute will be left with 5 after the change.
  3. “Drain” effect will use the component, and will create an “Absorb” effect, on each execution.
  4. The “Absorb” effect will add to an “Absorb” attribute, which will add Mana.

Feel free to use the above code!

Also feel free to comment on improvements/setbacks on this - these are always welcome!