Hi! I’m working through implementing the GameplayAbilities functionality similarly to how it is used in the ARPG sample project. For the most part I have it working, except for I can’t figure out how to make it really dynamic. Let me give an example:
The player equips an item from their inventory. This applies a GameplayEffect that gives them +100 max health. Simple enough so far. I can get all that to work.
BUT…in my game, items have randomly generated stats, so it might actually be +85 health instead of 100. So what I want to do is have a GameplayEffect, call it GPE_HealthBuff, and have the magnitude set programmatically instead of statically in the Data-Only blueprint for the effect. How can I do this?
I’m open to either Blueprint or C++ solutions. I suspect I have to somehow create a GamplayEffectSpec or something, just not finding a good example anywhere. I know I can do a custom calculation, but that seems like the hard way around for what I’m trying to do (also not sure how to get a reference back to the original inventory item within the calculation class, so…maybe not a good solution here.)
So, short version: How can I modify the magnitude or even the particular stat that a GameplayEffect alters at runtime, either through blueprints or c++?
This is a very general question and you can probably do it in multiple ways but here is my pick…
You should start with creating an effect_type enumerator (enum) like:
1-HP, 2-PhysicalDMG, 3-Mana, 4-Stun…
Next you should create a attribute structure (struct) like: effect_type effect; float value; some other values…
Now your item should hold a name, type, mesh, icon and attribute array to hold as many effects as needed.
Generation: You will probably generate your items based on the drop location (bosses drop different items than normal minions) so it is logical for the item generator to be part of the chest or minion… The generator should hold the rules for creating the items including generating their names, assign their meshes and applying the values of their attributes before spawning the items.
Applying: Every time an item is equipped you should modify your character values - what the attack animation is, how fast it is and how much damage the character does along with HP and all other things.
That’s generally it.
Now in real commercial projects, the generator is usually a separate class or sometimes a separate application (service) run on the server which generates the items on game-play servers’ requests based on some weapon templates from a large database. This is done in order for the items to be updated or tweaked without turning off the main game-play servers.
Thanks for the detailed attempt at an answer…but it’s not a general question and I think you’re misunderstanding what I’m asking. I already have my inventory system and item generation, that’s not the issue.
I’m talking specifically about the Ability System, and the GameplayEffect class. I can’t find a property or method that lets me set the Magnitude of a particular GameplayEffect modifier. I suspect the answer lies somewhere in the “SetByCaller” magnitude calculation type, but I’m finding it real tough to find an example…
I finally figured it out, I think. Adding how I did it here in case anyone else has the same question, since the existing Ability System docs are useful but lacking a lot of specifics, at least for my use cases…
So…First, in your GameplayEffect, you have to specify the Modifier Magnitude to be Set By Caller instead of scalable float. When you do that, you’ll be able to edit either a Data Tag, or a Data Name. (in theory…Data Name was non-editable for me, but I assume you SHOULD be able to edit that…)
You can then reference that Data Tag in your BP when you apply the effect, like this:
Char is my Character, which has an AbilitySystemComponent of course.
However, note that I was originally using ApplyGameplayEffectToSelf instead of ApplyGameplaySpecToSelf…minor difference in some cases, but I couldn’t find a way to get a handle to the GameplayEffectSpec using the simpler method, so I had to use that Make Outgoing Spec function to get the spec handle, which is required for the Assign Tag Set By Caller function.
Anyway…hope that helps someone else trying to figure this ability system out…
Just realized the screenshot I posted of the BP has a hardcoded “2” for the Magnitude…in the actual game that comes from the inventory item, of course. Don’t leave a hard coded value there, or you gain no benefit over just putting the value directly in the GameplayEffect definition.
As far as I know,
DataName is deprecated, so only use
Check of Modifier Magnitude Calculation. Its in blueprint. Search terms “ModMag” and you should see it when adding new blueprint. Then override the calculate base magnitude function.
Just wanted to say thank you)) very helpful
Hi, I’m trying to developing ARPG’s item system and impressed with your solution. I have a question about this.
On the other APRG games, It’s normal to save and load your items even if user closed the game. How to save the GameplayEffect’s randomly generated stats? Maybe use GetSetByCallerMagnitude and save this value?