Welcome to your next quest.
In this quest, you're going to use our melee attack montage and send a gameplay event to the actor
that owns this montage that's playing the montage.
Now we want to respond to a gameplay event in our gameplay ability.
We can just draw a debug sphere for now.
Now if you'd like a hint, look at how we're handling auras.
Firebolt.
Go look at our montage.
See how we're sending an event from that montage and how we're responding to that event in our firebolt
ability.
So when in doubt, if you've done something before, always go back and look at how you've done it before
to give yourself a guide for how to do it again.
So pause the video and conquer this quest now.
Okay.
So I'm going to close a couple things.
I don't think I need my behavior tree at the moment.
I actually closed my montage.
I think I did want that open.
That's okay.
I'm going to close my BT attack BP enemy base, BP or a character.
All that's fine.
I'm going to keep my melee attack open and let's think about what we're trying to do here.
We want to respond to a gameplay event now.
We can always check to see what we did in auras Firebolt montage so we can go to assets, characters,
aura animations, abilities and go to Am cast Firebolt.
And here we have an anim notify where we have chosen an event tag event montage dot Firebolt.
So what this anim notify does is calls send gameplay event to actor.
We can go to that by going to content blueprints and am notifies and opening an montage event as soon
as that notify has it's received notify function called it gets the owner and sends a gameplay event
to it using the event tag and you set the event tag from directly in the montage.
We can do this same thing.
So we're going to go into our attack montage for the Enemy for the Goblin.
So assets, enemies, Goblin animations, Spear.
And here's our attack Goblin Spear.
We're going to send an event, so I'd like to add a new notify track called Events and right about where
the impact point is right here, I'd like to send an event, so I'm going to right here.
I'm going to right click and we're going to add a notify and choose our custom anim notify Montage event.
Now we need to select an event tag and I don't have a tag for this.
I'm going to add one in project settings.
So edit project settings, gameplay tags and we have event montage firebolt.
And we didn't add this natively.
We added it within the editor.
And the truth is we don't need to access it from Cplusplus.
The same goes for the tag that I want for a melee attack event.
We don't need that in C plus plus.
So I'm just going to add it here.
Just next to Montage, I'm going to click plus to add a sub tag and have event dot, montage, dot attack
and we can even have attack melee so that we can have multiple types of attacks.
So event montage, attack, dot melee.
And now we have event montage attack melee.
We can use that now.
So back to our montage.
I'm going to choose the tag here.
Event tag is going to be event montage, attack melee, and then we can listen for that in our gameplay
ability Melee Attack.
So after playing a montage and wait, I'm going to disconnect this and move into ability out of the
way, the next thing we're going to do right away, we're not going to wait for any of our asynchronous
execution pins.
We're just going to use this topmost one and we're going to use wait gameplay event.
We're going to use the task.
So wait, gameplay event needs to know the tag.
We're going to use event montage, attack melee and we're going to only match exact.
So we match the exact tag and event received will be fired once we receive that tag.
So we can do something like draw a debug sphere, whatever we want.
Really.
I'd like to draw a debug sphere to make sure this works and I'd like to draw it at the combat socket
location.
I'd like to draw it right there at the socket on the weapon.
And if you'll recall, we can get that combat socket location because we have a combat interface with
a function called get combat socket location.
Now this is not blueprint callable, but we could easily change that, can't we?
Now, we know we're overriding this in all of our characters.
So if we change this to Blueprint callable, we're going to have to change it everywhere we're overwriting
it, which is not the biggest of deals.
It's a little annoying, but I do want to access the combat target location from Blueprint so that I
can draw a debug sphere around it.
So really quick, I'm going to close saving all my changes and I'm going to change this to a blueprint
callable blueprint native event.
That means we need to remove virtual.
We need to add blueprint native event.
Blueprint.
Callable.
I'm going to steal that from get hit React montage.
And now that we've made this change, then we have to make sure we're overriding the implementation
version in all classes that implement this interface.
So we're going to start at a character base.
So where's get combat socket location?
Let's see if we're overriding it here.
We are, we now need to override the implementation.
So implementation.
There we go.
And we need to make sure that it's got the implementation in the CPP file.
I'm going to search for combat socket location and replace it here.
So that takes care of it there.
Let's see if we have it in or enemy.
We're not overwriting it in our enemy.
Let's see about or a character.
We're not overwriting it there.
So we just needed to fix it in or a character base.
And all this does in our character base is checks the weapon and returns the weapon socket location.
Now, we should be able to call this from within blueprint.
Let's go ahead and launch the editor.
Okay, we're getting a linker error.
Get combat socket location is already defined.
Oh, and of course I have my default definition for it here.
We don't need that anymore.
We're going to remove that definition from combat interface CPP.
Now we compile successfully, so let's run.
I'll run it in debug mode.
Okay, opening my asset editors again.
I'm going to go to a melee attack.
I'm going to go ahead and close the Firebolt montage real quick.
And here in the melee attack, we can now get the combat socket location.
That's now a function on the combat interface.
So I can right click and type get combat socket location.
We now have this function and we need to pass in the avatar Actor.
I'm going to pass that in from the Avatar actor info.
Like so.
And now that we have the combat socket location, we can draw a debug sphere in response to the gameplay
event.
I'm actually going to move this call to just after wait gameplay event.
So on event received.
We'll get the combat socket location here and then we'll draw a debug sphere.
So draw debug sphere.
We'll pass in the combat socket location.
The radius can be small.
I'm going to make it 15.
I'm going to make the line color red.
I'm going to make the duration three seconds, and then I'll end the ability immediately after.
Okay.
Saving all.
I'm going to go ahead and press play and see if we get that little sphere at the tip of the spear.
There it is.
Now we get the sphere, but it's not at the tip of the spear.
It's actually it looks like it's at the location of the spear right at the beginning.
We may actually wish to double check that we're getting the correct socket location.
Let's see how we're implementing this in a character.
Get combat socket location.
It's using weapon tip socket.
Name on the weapon for get socket location.
So we need to make sure that that is correct for our goblin.
Let's go to our character folder into Goblin Spear.
Open that blueprint.
I'm going to check weapon.
Tip socket.
Name.
And sure enough, I see that it's not set, so I need to know what that weapon tip socket is so I can
go into the weapon.
I can select the weapon component, browse to it, and open that skeletal mesh editor and select my
tip socket.
And it's called tip socket.
So I'm going to click on this a couple times until I can copy tip socket back here and Goblin Spear,
I'm going to search for weapon tip socket name.
Again.
I have to select Goblin, Spear Self and I'm going to set this to tip socket.
Now that variable is set and we should be getting the actual tip socket.
So let's try this again.
Here we go.
And now we're getting that spear at the correct point.
Perfect.
So this is a great step in the right direction because as soon as our enemy attacks at that crucial
point in the attack where the point of the spear is at the sort of maximum extension there, we can
do anything we like.
In fact, we can visualize this better.
If I make the radius bigger, I can make this radius, say 45 for this debug sphere.
Sphere.
Kind of hard when I'm dealing with spears and spears at the same time.
But watch this now.
We have a bigger sphere at the tip of our spear.
And this is cool because it gives us some leeway if the enemy attacks and we're not exactly too close.
Well, this is a top down game.
Top down games usually give a bit of leeway, like, you know, a sphere of influence.
And if aura is in that sphere, we can cause damage, apply gameplay effects and what have you.
So this is actually a really great milestone.
The next step is to actually make that sphere cause us some damage and actually start hurting aura.
So we'll do that in the videos to come and things are starting to look great.
Interesting.
I launched a fireball at the enemy and we triggered a breakpoint.
And this is for the combat interface.
This is for jet combat socket location.
Interesting.
So let's see.
Let's follow the call stack and debug this little unexpected thing that happened.
Looks like we have send gameplay event to actor happening.
We're making it to spawn projectile.
And here in spawn projectile we're calling jet combat socket location and we got an exception for jet
combat socket location, the auto generated version of it because remember we made this a blueprint
native event.
So there's going to be some automatically generated code here in Gen CP, a file created for our combat
interface.
Now, what is it?
Checking that we failed, it says do not call event functions and interfaces call execute, get combat
socket location instead.
So we're actually calling the interface function directly.
But now we made it a blueprint native event.
So we have to call execute instead.
So let's go back to Spawn Projectile where we're violating this.
We're calling it directly.
Well, now we can't do that.
We have to actually call the execute version of that.
Remember, we're calling the execute version in Blueprint as well.
We just don't see that execute part of the function.
So let's do what this check is doing us here.
It says, do not directly call event call execute get combat socket location instead.
Why don't we do that?
So I'm going to go ahead and hit the stop and we're going to call, execute, get combat socket location
and or projectile spell.
So we do this by using eye combat interface, double colon execute and we have execute, get combat
socket location.
Now, when you call the execute version, you have to pass in an object.
This is a static function after all.
So we have to pass in the thing that implements the interface that's going to be this get Avatar actor
from actor info.
We're going to go ahead and pass that in and this returns that combat socket location so we can store
that in socket location here like so so giving it a semicolon.
Now this line is no longer necessary.
So that's how we can do that.
Notice now that we also don't even need to cast a combat interface anymore.
We could take the contents of this if combat interface if statement and replace the entire if statement
and the combat interface local variable with what was inside here.
So why don't we go ahead and try this out?
Okay back in the editor and.
Let's press play.
First.
We'll make sure everything else works.
So there's our sphere.
And of course, we lost some progress because I changed the weapon tip socket name in BP Goblin Spear.
But because we crashed, we didn't get that saved.
So I'm going to search for weapon tip socket name.
We called this tip socket, I believe.
I'm not going to check.
I'm just going to test my memory there.
And with that.
Let's see if we get it at the right location.
And we do.
And let's see if we can launch a fireball.
Oh, I missed.
There we go.
And we're doing perfect.
All right.
Excellent.
So this is all looking good.
I'm going to save all and we'll just really quickly go back to my gameplay abilities, melee attack
and change that radius back to 45 because I do want that to be larger.
I want to visualize this with a larger sphere because I do plan on causing damage to aura if she's in
that radius.
So excellent job and I'll see you in the next video.