Welcome back.
Now let's take a look at one of our gameplay effects.
I have Crystal Manor open here and I'm going to scroll down.
And because this gameplay effect has duration, we have the ability to configure its stacking options.
Notice we have a stacking section and we have a stacking type and stacking type can be set to none or
aggregate by source or aggregate by target.
Now it's set to none.
And I want to see what happens when we pick up two of these or maybe 3 or 4.
So I'm going to take this man a crystal and duplicate it a few times and I'll have these sort of all
next to each other so we can pick them all up very rapidly.
And let's see what happens with none as the stacking type.
I'm going to pick all three up and look at that.
Our mana goes up and in fact, let's look at the numerical value using show debug.
Our mana is set to ten and if I pick up all three of them, look at that.
It's going up really rapidly.
Now that seems like stacking, doesn't it?
But that's not what stacking really is.
Without any stacking, we just apply the effect three times.
Each one has its own duration and they're all sort of being applied at the same time and we end up getting
three times as much mana as if we were to pick up just a single crystal, right.
So that's the behavior without stacking.
So what behavior do we get with stacking?
Well, if we do have stacking and we choose one of these options, we can choose exactly what type of
behavior we see.
For example, let's say we wanted to pick up one crystal and that crystal has a duration of two seconds.
Well, what if during that two seconds we pick up another crystal?
What behavior would we want to see?
We don't want our mana increasing twice as fast.
Maybe we want to still just increase mana at the same rate, but we want to refresh that duration.
So say we pick up the first crystal and one second in, we pick up the second crystal.
Maybe we just want the duration refreshed so we get our mana increased for another two seconds.
It's things like that that are stacking parameters allow us to configure.
So the first two things we should talk about are these options for the stacking type aggregate by source
and aggregate by target.
How do these work?
So the first stacking type option, aside from none is aggregate by source.
Let's see how this works.
Let's say we set our stack limit count to two.
Well, aggregate by source means that that stack limit count is enforced per source.
So if we have one source and it applies a gameplay effect to the target, we count that as one stack
of the gameplay effect and it's aggregated on the source.
So the source now has one stack count for this gameplay effect applied to the target.
Now the same source applies that same gameplay effect again, right?
And we count this as the second stack and that's aggregated by the source.
Now at this point we have two stacks of the gameplay effect and that's the limit.
We set our stack limit count for this effect to two.
So if the same source applies the same effect, again this would be the third stack, but that exceeds
the limit.
So this effect can't be applied.
Now we're aggregating by source, which means each source keeps a count of the stacks of this particular
effect caused by the source.
So say we get another source in the game that applies this same gameplay effect.
Well, we're aggregating our stacks by source.
So for this source, this is only the first stack.
And so we aggregate that stack by that specific source.
So now the target has two stacks of this effect applied from the first source and one stack applied
from the third.
Now that may seem to exceed the stack limit count, but we're aggregating by source so we can have a
maximum of two stacks per source applied to the target.
Now let's compare this to the other option aggregate by target before we were aggregating by source.
Now we're aggregating by Target.
So say we have a source.
It applies the gameplay effect.
This counts as a single stack and this stack is aggregated by the target this time instead of the source.
Now that same source applies the effect.
Again, this counts as the second stack, and that's added to the stack count which is aggregated by
the target.
Now the same source can attempt to apply another stack.
That would be the third one, but of course that exceeds the stack limit count, right?
So as we'd expect, that stack cannot be applied.
But along comes another source attempting to apply this effect.
And if we were aggregating by source, this source hasn't applied any stacks yet, but we're aggregating
by Target and the target already has two stacks applied.
So for this new source attempting to apply this effect, this would be the third stack on the target
and the stack limit count is two.
This would exceed that.
So this effect cannot be applied.
So that's the difference between aggregating by source and by target.
By source means there's a limit per source, but by target means there's a limit per target.
So in our case, let's say we choose aggregate by source and we set a stack limit count of two.
Now the duration I'd like to set to one second to make our math simple here.
And the period is going to be 0.1 and I'm going to uncheck execute periodic effect on application.
Now, this means that for one second we'll execute our modifiers ten times, and because we're adding
one to our mana, we should see a total of ten added to our mana over the space of a second per mana
crystal.
Right.
That makes sense.
So let's duplicate one of the crystals and move it over here.
Press play show debug ability system and we see that our mana is ten and if I pick up a single health
crystal I should see it go up to 20 within the space of a second.
Makes sense.
Okay, now we set our stacking type to aggregate by source with a stack limit count of two.
Well, what do we mean by source?
Source is referring to actually an ability system component that's causing this.
So we're causing this effect by actors.
So in our case, it doesn't matter if we choose source or target, we're going to get a stack limit
of two and forced.
So we should only see our mana go up by 20 total.
So we have ten.
If we pick up all three, we go up to 30, which is 20 more than we had before.
So once we start having ability system components as the source, we should start being able to test
that out.
Now we have a stack duration refresh policy and it says policy for how the effect duration should be
refreshed while stacking and it's set to refresh on successful application.
If we choose never refresh, then even though we're adding stacks, that duration of one second is what
prevails.
So if we set this to never refresh and we go on to pick up some mana crystals, I'm going to show debug.
We have a mana of ten, I'm going to pick one up and then pick up another notice.
We didn't get all the way up to 30 because that full second had elapsed before we reached 30.
So it doesn't matter how many stacks we have.
This effect will expire at the end of a second, no matter what.
But with refresh on successful application, each time we stack another one on it resets the duration
and you get an additional second.
Now we have a stack period reset policy and this is similar to the duration refresh policy only.
It's for the period itself.
So if you're waiting for the next periodic change to an attribute, when we stack a new stack of this
effect, reset on successful application means reset that period and start waiting for another full
period.
Otherwise, never reset means well, we won't reset that period and expiration policy is set to clear
entire stack, which means as soon as this effect expires, all of the stacks are cleared.
But you can choose to set this to remove single stack and refresh duration, which means that as the
duration finishes, we remove a single stack and then the duration starts over again.
So you can have two of these effects stacked on and when the duration expires, the stack count goes
down to one and then the duration count starts over again.
So as you can see, we have a lot of options when it comes to stacking.
And it really just depends on how you want these things to stack in your game.
And throughout the project, we'll be creating lots of effects and choosing how they can stack.
For now, for the Manna Crystal, I'd like to leave it at aggregate by Target with a stack limit count
of two.
I'd like to refresh the duration on successful application.
I'd like to reset the period on successful application and as soon as a stack expires, I'd like to
clear the whole stack and the duration can be left at one.
And the stack expiration policy.
I'm going to set to remove single stack and refresh duration.
That way, as we pick up more and more crystals, then we extend the duration and we can potentially
gain more mana.
So if I spread these out, we can kind of see the result of this combination of parameters.
So I'm going to press play.
I'm going to show debug and I have ten mana.
If I pick up one, I just get ten more mana.
If I pick up another one and then another one.
I got 20 more, and that's because I refreshed that duration when I got a new stack.
But if I start off with ten and I pick up all four of these.
Notice that I only go up to 56 and that's because I'm picking them up one after the other and each time
I pick it up, I reset that duration.
And notice that no matter how many stacks I have, I'm always just gaining one mana every 10th of a
second.
Whereas if we didn't stack at all, if I set this back to none, then picking up a whole bunch of these
results in a very fast increase in mana and setting it back to say, aggregate by target with a stack
limit count of one, for example, then we can continue prolonging the stack duration but always get
the same rate of increase of mana.
So let's pick up all of these and we'll see that we increase that duration, but we're only ever getting
one mana.
Ten times a second because we're limiting to one stack.
So picking up a crystal before the previous stack expired simply resets the duration.
So I know it's kind of a lot to take in, but we have a lot of options here and we'll see how they can
be combined and set up throughout the course.
Now, the last of the stack expiration policy is refreshed duration, which means that when this stack
expires, refresh the duration, even if it's the one and only stack.
This essentially makes the effect infinite in duration because it keeps refreshing.
So the comment says this can be used to manually handle stack decrements via on stack count change callback.
So there's ways to respond to when the stack count changes and we'll get to that.
But if I set this to refresh duration, watch what happens if I pick up just a single crystal.
We see that it keeps going and it never stops because each time the stack expires, we refresh the duration.
So that's a way to get a sort of infinite duration, periodic effect.
I'm going to go ahead and leave this at clear entire stack.
That way as we can pick up multiple ones, we'll clear the stack completely as soon as that duration
runs out.
And before we wrap up, why don't we just go to the Crystal Heal gameplay effect and set its stacking
type?
I'm going to set it to aggregate by target, set a stack limit count of one and just like Crystal Manna,
we'll leave it at refresh on successful application and reset on successful application.
And just like Crystal Manna, we'll leave it at clear entire stack as well.
And that way we've got a little bit of throttling if we pick up too many at the same time.
So great job we now know about stacking and I'll see you in the next video.