Welcome back.
We're now going to talk about the modifier order of operations.
Now, we've seen that when we just add multiple modifiers and they're all affecting the health attribute
and they all have their modifier op set to add, then the result is pretty simple.
We take our health attribute and add the value of the modifiers backing attribute.
Here we have first, our vigor attribute backing the first modifier and then we have our strength attribute
backing the second.
And as you would probably guess, if we added another one and we chose the health attribute yet again
for this one, we left it at Add.
And if we set the magnitude calculation type to attribute based and we set our backing attribute to
yet another attribute such as resilience, choosing our attribute source to be target, then I think
you could guess what's going to happen, right?
Obviously the attributes will be added together.
So starting at a health of 50, if we overlap, we see that our health becomes 81, which is 50 plus
nine plus 12, which is resilience plus ten.
That all equals 81.
So it's as expected.
But let's talk about what happens if we change these modifier operations a little bit.
And as we're making different changes, I'd like to make the math simple for us.
So I'm going to go ahead and close out.
And in the attribute set, I'm going to initialize the health to ten just so we can make our math a
little bit easier to understand.
So let's talk about the different operations.
So we're now initializing our health to a value of ten, and we know that we can add a modifier to a
gameplay effect.
Choosing an Attribute to effect.
So far, we're just affecting the health attribute.
We choose a modifier operation such as Add and for attribute based modifiers, we choose the backing
attribute.
So in this case, if we choose vigor and our vigor just happens to have a value of nine, then we know
that nine will be added to the health.
Likewise, if we add another modifier set to target the health with an add modifier op with the backing
attribute of strength and our strength is ten, we know the result will be that ten will be added to
the health as a result of this modifier and likewise with another add modifier backed by the attribute
resilience, which is 12.
We know what happens.
12 gets added to the health as well.
Now these happen in order.
So the first modifier is applied, then the second, then the third.
And the result is that our health, the affected attribute gets the addition of the first modifier.
That's vigor plus the addition of the second modifier.
That's strength plus the third.
That's resilience.
And the result of this calculation comes out to 41.
Our health was ten and we added nine plus ten plus 12.
So let's just make sure that that math adds up.
We initialized our health to ten.
Now let's run this.
We can go ahead and open up our asset editors and our test attribute based gameplay effect has three
attribute based modifiers just like in the slide.
The first is backed by the vigor, the second is backed by strength, and the third is backed by resilience.
And they are all set to add.
Now we're starting off with ten health as we can see when we show debug and if we overlap, our health
becomes 41, just like in the slide.
So our understanding of the order of operations with add modifier ops is correct.
Now let's consider a more complicated case.
Let's say that the first modifier is backed by vigor and it's Add just like before.
But the second modifier, which is backed by strength, is now set to have multiply as its modifier
op.
And the third modifier is still resilience and still add.
So the only thing we're going to change here is that that middle modifier is set to multiply.
Now, as we've mentioned before, these happen in order, so the first modifier is applied, then the
second, then the third.
So the mathematics of this is as follows.
We have our health, the first modifier is applied, so we add vigor.
Ten plus nine is 19.
So the result of this then has the next modifier applied to it.
So that 19 is going to be multiplied by ten.
That gives us 190.
Then the next modifier takes the result of that and applies its modification.
We're adding 12, so we have 190 plus 12.
That equals 202.
Let's see if this math checks out.
So back in our test attribute based, we want to change that middle modifier so that its modifier op
is now multiply.
So we'll change that.
The other two are still Add.
Let's go ahead and press play show debug.
Health starts at ten and as we overlap we see that our health is actually 100 because we're clamping,
aren't we?
Let's go ahead and undo that clamping.
I'm going to close the editor and back in our attributes set.
We're clamping and pre attribute change.
I'm going to comment out both of those lines.
Really, we just care about health right now, but I'm going to comment those lines out and here in
post gameplay effect execute I'm going to comment out the lines where we're clamping here as well.
And I'll go ahead and run in debug mode.
Okay.
So now that we're no longer clamping, I'll go ahead and open up those asset editors and we'll make
sure the modifier op for the middle modifier is set to multiply.
It is.
And now that we're no longer clamping, let's see if we get the value we expect.
And just to remind ourselves, we're expecting a value of 202 here so we can press play show.
Debug health is ten and as we overlap with this volume, health goes to 202, which is exactly what
we expected.
So we see that these modifiers are applied in order.
Now let's consider another case.
Our health starts at ten.
Our first modifier will still be vigor and will still be add our second modifier that will still be
backed by strength and will keep its modifier op at multiply.
But the third modifier, let's say we change that one.
So now our resilience instead of Add is now going to be a divide modifier op.
Now this is going to work just like before in that the first modifier will be applied, then the second,
then the third.
So it's going to take our health value, which is ten.
We'll have the value of vigor added to it.
And the result of this, which is 19, will then be modified by strength, just like before.
That gives us 190.
And then the result of this, which is 190, is going to have the third modifier applied, which is
to divide resilience.
That's 12.
So the result should be 190 divided by 12.
If we pull up a calculator, we're going to have 190 divided by 12, which gives us 15.83 repeating.
So we see that the result of these three modifiers should give us 15.83 for the health.
Let's see if that math checks out.
So we'll go to our test based attribute and we're going to leave the first two modifiers as they are
and take the third one and change it from add to divide.
Let's go ahead and test this out.
We'll show debug.
Our health is ten and as we overlap, our health becomes 15.83.
And again, that's the value we expected.
Okay.
So we understand that well, so we know that these are applied in order, right?
So what happens if we add a fourth modifier?
Let's say that it's backing attribute is max health and it's modifier op is set to add.
So how does this change things?
Well, the results of the first three will simply be modified by the fourth one.
So we get our health, we add vigor.
That's the first modifier, the result of this is multiplied by the strength.
That's our second modifier.
The result of this is divided by resilience, and the result of this entire thing will then be added
to by max health.
So before it was 15.83, we're adding 100 to that.
So the result should be 115 .83.
Let's make sure that math checks out.
So back in our gameplay effect, we're going to add one more modifier to the modifiers array.
We're going to expand it.
We'd like our attribute affected to be health.
We'd like to use Add for the modifier OP for modifier magnitude.
We're going to change it to attribute based and expanding attribute based magnitude and expanding backing
attribute.
We're setting the backing attribute this time to max health, which is 100, and we'll go ahead and
set that attribute source to Target.
And we're expecting to see 115 .83.
Let's press play show debug and overlap and there it is, 115 .83 just as expected.
So now that we understand the order of operations of our modifiers in a gameplay effect, we now can
mix and match and make a gameplay effect.
Change an attribute based on any number of other attributes.
And we can structure this to get a lot of different results.
But you're probably wondering under attribute based magnitude what these three parameters are coefficient
pre, multiply additive value and post multiply additive value.
Well, the truth is we can make the mathematics even more customized by specifying values for these
and we're going to see how they work in the next video.
So great job.
I'll see you soon.