GameplayEffect: How to set magnitude programatically?
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++?
asked Aug 28 '18 at 04:30 PM in Blueprint Scripting
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...
answered Aug 29 '18 at 12:53 AM
This is a very general question and you can probably do it in multiple ways but here is my pick...
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.
Happy coding :)
answered Aug 28 '18 at 11:16 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here