Welcome back.
Now, we've seen a little bit about how ability tasks work by looking at play, montage and weight.
Now, there's a lot here that seems still a little bit cryptic.
We know that all the parts connect together, but the way they all connect together is still a little
bit hazy because we haven't really created one of these of our own yet.
So don't worry, we'll get some experience creating some tasks of our own and seeing exactly how they
work.
I just wanted to show you that play montage and weights is defined by this ability task class.
So we'll get to more of the inner workings of tasks later.
But for now I'd like to learn how we can do something in response to reaching a point in our montage
because we'd like to delay spawning that projectile until we've reached a certain point right about
there in the montage.
Now, you should be familiar with with anim notifies.
They're pretty standard and you can add them to montages and animation assets by simply right clicking
down here in the notify section where you have one or more notify tracks.
Now, I'd like to make a notify though that's custom.
That has more capabilities.
I'd like to trigger something in response to reaching this notify.
What I'd like to do specifically is send a gameplay event so gameplay events can be sent along with
data to a given actor and a gameplay ability can listen for events.
We have an ability task for that.
So I'm going to go ahead and remove these print strings.
I'm going to delete them all and immediately after play montage and wait, I'm going to drag off and
type wait gameplay event.
Now this goes under ability and we have wait gameplay event to actor and simply wait gameplay event.
We're just going to choose the basic wait gameplay event.
This will wait for an event to be sent to the actor that has the ability system component that's activating
this ability.
Now we specify when we're waiting for a gameplay event, what event we should wait for and the event
is identified with a gameplay tag.
So what we can do is create a gameplay tag designed to identify specific events such as, Oh, I don't
know, launching a fireball.
And since the gameplay tag for this event is not something we need to access from Cplusplus at the moment
I can simply add that gameplay tag to my project in project settings.
So in project settings going to gameplay tags, I can add a new gameplay tag and this is going to be
an event gameplay tag and our gameplay events can be of different kinds.
So I'd like to have a subcategory montage and I'll call this Firebolt.
So if we want to spawn a Firebolt from a montage, then we'll send an event that has this gameplay tag.
So hitting enter we see that we now have event montage firebolt and in our firebolt our wait gameplay
event can specify that it's waiting for an event to be sent.
With this event tag, we're going to set that tag to event montage firebolt and we can see it right
there.
So now all that we need to do is send that gameplay event and I'd like to do that in a custom anim,
notify that we're going to stick right there in this montage.
So let's make that notify.
I'm going to make a new folder in blueprints right here called Anim Notifies.
We'll go into this and we'll make a new blueprint class based on the anim notify.
So we're going to do a new blueprint class.
We're going to search for anim.
Notify and choose anim notify.
We'll go ahead and create that.
And I'm just going to call this an underscore montage event.
And this will be used for any montages that wish to send a gameplay event.
So we'll double click to open this up and the function on this notify that we need to override is called
received notify.
So if we click on functions override dropdown, we can override received notify and we can decide what
happens here when the notify is reached.
This function will be called when we reach the notify and we have the mesh component associated with
the animation montage that's executing this notify and we can always get the owner of that mesh.
With get owner.
So we have the owner and that's an actor.
Now, how do we send a gameplay event?
Well, if we right click, we can simply type send gameplay event and here's send gameplay event to
actor.
We can see that its target is ability system Blueprint library.
So this is in that static library, which is why it's accessible here.
It's very useful.
And if we send gameplay event to actor before hitting the return node, then we can specify the actor.
That's why I got the owner.
So we can pass the owner in there and we can specify the tag.
And there's also an optional structure called payload.
So as we send a gameplay event to an actor, not only are we sending an identifying tag, we can also
send additional data through the payload.
And if we go back to the firebolt, we'll see that wait gameplay event has this payload output and it
also has this event received execution wire.
So as soon as the owning actor receives the event, this event received will be executed and will receive
the payload.
Pretty nifty.
So here in our anim notify, we're going to set the event tag.
Now, we don't want to hard code this.
We want this to be a variable on this anim.
Notify that we can set from within the montage.
So we're going to add a new variable and we're going to call this event tag.
We're going to change its type to gameplay tag.
And we're going to check the eye icon to make it editable.
And we're going to pass the event tag in right here.
Now, if you're curious what this payload contains, we can drag off of it and select make gameplay
event data.
And if we expand it, we see that the payload is of this structure type gameplay event data, which
can contain lots of information such as a tag, an instigator, a target, two optional objects that
you can set to whatever you want.
A context handle instigator tags, target tags, an event magnitude which you can use for whatever you
want, and even target data, which is another type of structure that can contain even more information.
So payload can contain potentially a lot of info in it.
We're not going to use it for this, though.
We're just going to send the event tag.
So compiling and saving this anim notify class.
We can go back to our montage and we can add a notify.
So right here in the one track, I'm going to right click add, Notify, and right here under the search
bar, we have our custom anim notify and montage event if I select it and then click on it here, then
in the details panel because I exposed my event tag variable.
It's right here and we can expand the dropdown and choose the tag we wish to associate with this cast
Firebolt montage.
So I'm going to choose Firebolt now when our montage reaches this point, then received notify on this
anim notify class will be called.
It'll get the owner of the mesh comp and it'll send the event tag via send gameplay event to actor and
that will result in the gameplay event with this event tag being received.
And because this node weight gameplay event means that we're waiting for a gameplay event with the firebolt
tag, then this event received will be executed.
Let's just print a string and we'll say Firebolt event received.
We'll go ahead and make this a yellowish orange color.
And let's activate our ability.
So hovering over an enemy.
Clicking.
And there was a little bit of a delay before we saw that message.
It's really fast, so it's kind of hard to see.
We could slow the montage down to say, 0.1.
And now if we play the montage.
Then we don't get that message until we reach that point in the montage, which is greatly slowed down.
Boom, right there.
And of course, we're spawning the fireball immediately.
That's because we're doing it in our C plus plus function for aura, projectile spell activate ability.
So we're going to want to change that, of course.
But we see that now we're receiving an event thanks to our custom anim notify which calls the ability
system blueprint library function send gameplay event to actor.
We can call this in C plus plus even.
So now we know how to receive events via wait gameplay event in our gameplay ability.
So now what we need to do is make sure that we're spawning our projectile only when we receive this
event.
We don't want to spawn it immediately because it doesn't look right.
You see, we should spawn it right there when we receive that event.
So I'm going to go back to my montage set the rate scale back to 100 or 1, which is 100%.
And in the next video, we're going to go about only spawning the projectile when we receive the gameplay
event.
Excellent job.
I'll see you in the next video.