Our team has built some Blueprint content in Unreal 4.26 where they group a set of stat modifiers into a single permanent GameplayEffect and apply it to the player character. These modifiers can change based on what the player has equipped, and so the GE is periodically reconstructed using MakeOutgoingSpec() and re-applied.
Currently when this reconstruction happens, they are re-applying the GE with stacking behaviour enabled and a stack count of 1, which doesn’t update the modifiers since the stack count is capped at 1. To address this, they added a workaround of calling SetActiveGameplayEffectLevel(0) to force the modifier magnitudes to get updated. This no longer work in 4.27, since SetActiveGameplayEffectLevel now aborts if the level hasn’t changed.
What is the correct way to achieve the desired behaviour of updating modifiers in an existing GE? Remove old one/readd new one? I’m told there are some problems with this approach b/c of external systems receiving callbacks containing the transient state of the modifiers, but have to investigate that part further.
Are you open to alternative solutions? Because it would be way cleaner if each weapon/item had its own gameplay effect that modifies the relevant attributes. Apply the effect when the item is equipped and remove it when the item is unequipped. This can be extended to wearables, potions, even world states like the time of day or how dark it is. Your current solution does not sound like it scales well.
Thanks and-rad. Yes, I was curious about that approach as well (as a longer term fix) for the same reason. I’ve sent the thread link to our game designers for their consideration.
In the short term, is add/remove the recommended approach?
I can’t say with certainty whether it’ll work or lead to subtle bugs. It sounds like it should work, but “recommended” is not a word I’d use, even short term. Better wait for input from others on this.
We do the same that @and-rad said. We give GE’s when item is equipped and remove them when item is unequipped. Our items do not have any ASC’s. Player has a weapon attribute set that we modify for things like recoil, weapon crit chance, etc. But this is mutated by effects.
The entire Gameplay Ability System is built around having many, many, small modifiers, that each add some particular kind of effect.
You’re essentially Doing It Wrong.
Taking a “wait and see” attitude will just lead to more maintenance and bugs and headaches. My suggestion is you realize you have to do this, and you do it sooner, rather than later. Pushing away code changes you know you have to do, is never the right choice, in my experience.
(Also, note that you can apply many statuses with a single effect, if needed.)