Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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++?

Product Version: UE 4.20
more ▼

asked Aug 28 '18 at 04:30 PM in Blueprint Scripting

avatar image

56 2 7 9

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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...)

alt text

You can then reference that Data Tag in your BP when you apply the effect, like this:

alt text

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...

healgpe.png (86.5 kB)
makespecbp.png (134.2 kB)
more ▼

answered Aug 29 '18 at 12:53 AM

avatar image

56 2 7 9

avatar image AngularRat Aug 29 '18 at 12:55 AM

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. ;-)

avatar image Roi Danton Nov 23 '18 at 12:06 AM

As far as I know, DataName is deprecated, so only use DataTag for SetByCaller.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

This is a very general question and you can probably do it in multiple ways but here is my pick...

  1. You should start with creating an effect_type enumerator (enum) like: 1-HP, 2-PhysicalDMG, 3-Mana, 4-Stun...

  2. Next you should create a attribute structure (struct) like: effect_type effect; float value; some other values...

  3. Now your item should hold a name, type, mesh, icon and attribute array to hold as many effects as needed.

  4. 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.

  5. 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.

Happy coding :)

more ▼

answered Aug 28 '18 at 11:16 PM

avatar image

1.3k 6 5 9

avatar image AngularRat Aug 29 '18 at 12:36 AM

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...

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question