Welcome back.
Now, we just learned about ability costs and we also learned about cooldowns.
A little bit.
We saw that in the game play ability.
We have the ability to apply costs.
We can also apply Cooldowns as well.
And notice that this applies a gameplay effect and a cooldown gameplay effect is going to prevent us
from being able to activate an ability until the cooldown time has elapsed and in order to have a cooldown
gameplay effect, we need a cooldown tag for it.
So the first thing we're going to do to implement cooldown is I'm going to close all my tabs and open
my aura gameplay tags and we're going to create a cooldown tag for our Firebolt ability.
So I'm going to have this right here under my abilities tags.
It's going to be just like abilities Firebolt except it's going to be cooldown fire Firebolt.
Let's go ahead and create that.
So here's my Firebolt I'm going to copy and paste it down here and it's going to be cooldown fire Firebolt
and the name will be changed to cooldown Fire Firebolt and its string will say Firebolt cooldown tag
and I'm going to have a multi-line comment to show that this is where we're going to have some cooldown
tags.
So I'm going to say cooldown here.
And now we have a cooldown tag.
Perfect.
So let's implement cooldown for our firebolt.
I'm going to go ahead and launch.
And with the editor open, we can create our cooldown gameplay ability and I'm going to go into ability
system or abilities, fire Firebolt and create that gameplay effect here.
So new blueprint class gameplay effect choosing gameplay effect.
We're going to create a new g underscore cooldown underscore Firebolt Now how to cooldowns work?
Well, we've seen that when we commit a cooldown we're applying this gameplay effect to ourselves.
Look at the code.
I'm going to search for it again.
I'll just go ahead and open gameplay ability and scroll up a bit because we have apply cooldown, right?
And what does apply cooldown do?
Well, we can go to it.
We see that it applies a gameplay effect to owner.
So what does this mean?
Why is that going to prevent us from activating an ability?
Well, it will work as a cooldown tag if we add a granted tag and that granted tag has to be a cooldown
tag.
So if we add our new cooldown tag cooldown dot fire dot firebolt to the granted tags, then our ability
system component will now have the cooldown tag that is going to prevent the ability if and only if
this cooldown effect is set as the cooldown effect for the ability.
But that's not the only thing.
These are durations, right?
This is a cooldown with a duration, which means it can't be instant, it has to be a has duration.
And it's also going to need a non-zero duration magnitude.
Right?
For instance, we can put a one here.
And of course, scalable floats.
You already know they can have curved tables.
I'm just going to have a one second duration on and then with that we can open our firebolt and scroll
down to the bottom and give ourselves a cooldown.
Gameplay effect class that's going to be cooldown Firebolt.
Now if we're committing and we are calling commit ability, which commits both cost and cooldown, if
we're committing our cooldown gameplay effect, that means it's applied to the owner of this gameplay
ability.
And because this gameplay effect grants, the cooldown tag are owner of this ability is going to have
the cooldown tag and if it has the cooldown tag that is associated with the cooldown gameplay effect
set here in the class defaults, then we won't be able to activate the ability until that cooldown tag
is removed.
So now we don't need this delay hack.
We're going to remove that delay from the ability and after spawning the projectile we can end the ability
immediately and we don't have to worry about being able to spam it.
We'll have to wait a full second before we can activate it again.
Let's test that out and I'm spamming the left mouse button and I can only fire once every second, and
then when I run out of mana, I can fire it all.
Now, one second is too long.
I just wanted that to be a sort of demonstration time, but 0.5 is probably a little bit better.
We don't want our weakest ability to be over nerfed.
We don't want it to be too weak to be used as early on in the game.
Things should be quite easy.
So half a second, pretty good delay.
So that's all great.
That's all fine.
But really all we perceive is that delay physically as we're trying to activate the ability again,
we can click, click, click, click, click and only activate it once every second, but we get no
visual feedback.
As far as the duration of that cooldown.
Usually RPGs have visual feedback showing you how much of that cooldown time has elapsed, and typically
that's down somewhere where we have our ability icons, right?
So I have my left mouse button ability icon here.
It'd be nice if we can see the cooldown time remaining and we could have this grayed out so we know
we can't activate this ability until the cooldown has elapsed and we can then cast it again.
So in the videos to come, that is going to be our goal, to implement a cooldown timer that shows us
visual feedback for those Cooldowns.
So excellent job and if you feel like it, go ahead and make yourself a curve table for the cool.
Downs if you want the cooldown duration to change with the level of our ability.
I don't.
I want the cooldown to be a 0.5 constant rate for my firebolt ability.
But that's just me.
Now, one last detail you might have noticed while testing before we wrap up this video is now that
we've removed that delay before ending our ability.
You'll notice that our montage is cut short and that can easily be fixed if we go into our firebolt
ability and uncheck this checkbox from play montage and wait stop when ability ends.
If we uncheck that, then our montage will continue playing even past when our ability ends as we're
ending it quite early.
So if we press play now, we'll see that we get that full.
Montage.
And of course, if we activate the ability, we're playing that montage again.
So if it's still finishing up, we'll start that montage all over again.
And that's the sort of behavior that I'd like.
Now this is all fine and good, except if we change this to a multiplayer game with two players, let's
see what happens on a client.
Notice we're not getting our projectile spawned.
Now, this has to do with ending the ability.
If we end the ability this soon, then what's happening here in the pie is that ability is ended instantly
on the client before the projectile can even really be spawned.
So to prevent that, we don't have to end the ability as soon as we spawn the projectile, but rather
we could tie this to ending the ability once the montage is complete.
In fact, we could end the ability really any time a good deal after the spawn projectile function is
called.
So we could hook up all of these, including blend out, interrupted, canceled.
We'll end the ability for any of these and that's going to take care of allowing the client enough time
to actually spawn that projectile.
And of course our server is also able to launch.
So now things look good in multiplayer.
Excellent job and I'll see you in the next video.