Welcome back.
We're going to continue our work with our electrocute ability.
But if we go to class settings we see that it's based on or damage gameplay ability our base damage
gameplay ability class.
Now electrocute is going to be one of the more advanced gameplay abilities we create in this course.
It's actually going to have a lot to it, and that means we're going to need a base C plus plus class
behind it, because there will be some algorithmic operations, and for algorithms, it's best to do
those in C plus plus and expose those to blueprint.
It's always more performant to call a blueprint callable function that has C plus plus code underpinning
what it does, rather than a blueprint function that has its logic all scripted out in blueprint.
It's much more performant and fast to do the heavy lifting in C plus plus, and that's why we can get
away with having the majority of our logic flow in a gameplay ability blueprint, because we're wise
about keeping those computationally intense algorithms on the C plus plus side.
So we're going to create a new gameplay ability for our electrocute, but really, it's a spell that
casts a beam.
And just so we remember the end goal here, if we go to Effects Shock and check out this beam, we have
a beam of electricity.
So the spell is concerned with some kind of a beam effect.
And we're going to flesh out the mechanics of that type of gameplay ability.
So we're going to make an aura beam spell.
So we can go to C plus plus classes or public ability system abilities.
And we'll make a new C plus plus class.
And this needs to be a damage gameplay ability.
So we're going to base this on aura damage gameplay ability.
We'll create a new C plus plus class derived from this.
And we're going to call this Aura Beam spell.
We'll go ahead and create the class and close the editor down.
All right, there's aura Beam spell CP, and I'll open the H file as well.
And now we have the C plus plus class.
And as we're constructing our gameplay ability we'll be coming back to this class and adding things
to it and using it in the electrocute blueprint, which we now need to reparent to or a beam spell.
So we're going to do that next.
So launching the editor.
We'll go ahead and get that ability back open.
I don't think I need BP or a character or Firebolt at the moment.
I'm just going to come back to electrocute, come to its class settings and change them from aura damage
gameplay ability to Aura Beam spell.
Now we can use that as our parent class to underpin what goes on in here.
Now, I think I'm done with all these print strings, at least for now.
You know how much I like my print strings, but I'm going to get rid of them for now.
We'll keep the weight input release.
We're going to be using that.
Right.
But let's think about what's happening here.
When we activate electrocute we're pressing some kind of input.
We're going to need to get some target data under the mouse.
Just like for the Firebolt spell.
If we launch a Firebolt we've clicked somewhere.
Right.
And that means we're going to need a location and really just a full on hit result for that place where
we're clicking.
And it doesn't matter if our input is a left mouse button or right mouse button, even one of the number
keys or anything else.
All that matters is where our mouse is at the time, so we can get that target data under the mouse
with our custom ability task.
Target data under mouse.
We'll go ahead and get one of those first thing.
And as soon as we have valid data.
Then we know that we'll have our data handle, which if we go ahead and call, get hit result from target
data.
Then we know that we can get from our hit result really anything we want.
The things we're most interested in are the impact point, not impact normal and the hit actor.
Those are the things we're most interested in.
And since we'll be using that impact point and the hit actor all throughout the game play ability,
right, we're going to need to know where to set the end location for our beam when we spawn it.
And we're also going to need to know who the hit actor is, if we're going to cause damage to it and
things like that.
We're going to want to store those.
We can promote those two variables, right.
But because we're going to probably want to use these in our algorithms, some of which we may program
in C plus.
Plus, it might be a good idea for this spell to have a hit actor and a mouse hit location variable
a C plus plus variable that we can set from blueprint and that's going to make things easier for us
in C plus plus.
Now in addition to this while I'm in the shock loop.
In other words, while I'm electrocuting an enemy and that beam is showing, I'm going to want to hide
the mouse cursor, and I want that cursor to come back as soon as I have released my input.
And for that reason, I'm also going to want the owner controller, a player controller variable that
we can get as well.
So I'm going to want variables for those.
And we can also make a blueprint callable function to pass info into so that we can set those variables
values.
So I'm going to go ahead and close the editor and add some things to my beam spell.
And we'll go ahead and make a public section and a protected section.
And in the protected section is where I'd like my variables.
So first I'd like to store my mouse hit location as an f vector called mouse hit location.
And I'd like to be able to set this from within the blueprint, which means I want it to be blueprint.
Read, write.
I'm going to go ahead and stick this in the category.
Of beam.
And I'll go ahead and make an A actor pointer.
That'll be a T object pointer to type a actor called mouse hit actor.
And this one will also be blueprint.
Read.
Write.
Now we're making a blueprint read, write.
But I would also like a nice function that can take in that hit result and set those properties for
us.
So I'm going to make a void function for caching off our pertinent values that we need here in this
ability.
So we can make a store mouse data info.
Which can take in a const f hit result by reference, and we can call this hit result.
And we'll make this a new function with blueprint callable.
Now I mentioned we'll want a player controller as well.
So I'm going to make a t object pointer of type A player controller.
And we'll call this owner player controller.
We'll make this also blueprint.
Read.
Write.
And we'll just go ahead and make a separate function for setting this.
Store owner.
Player.
Controller.
And we'll make this blueprint callable as well.
We can handle storing it in store mouse data info, but store mouse data info has a function name that
doesn't indicate that it does that at all.
So we'll just go ahead and have two separate functions that take care of these.
I'll go ahead and generate these function definitions.
In storm mouse data info can check to make sure if the hit result dot be blocking hit is true, and
if it is, we'll get that mouse hit location and we'll store it with our hit result dot impact point.
And we'll also get our mouse hit actor and we'll store that as well with hit results.
Dot get actor.
Now if our hit result doesn't get a valid blocking hit, we can simply cancel the ability with cancel
ability.
Now, to cancel the ability, we have to pass in some things.
But inside of the game play ability, we have those things.
The first is the ability spec handle we can pass in current spec handle we just automatically have access
to that.
It needs the actor info.
We can get current actor info, pass that in, and then it wants to know if we should replicate this
canceling of the ability.
And we also need the activation info we can pass in current activation info.
We have that as well.
And finally a boolean for whether or not to replicate canceling this ability we can pass in.
True.
So now we have our mouse hit location and mouse hit actor.
If we call this function and to store the player controller, we can get the current actor info.
And we have access to the avatar actor.
We have access to the player controller.
So really, it's not that important to store this as a variable as we already have this.
But what we can do is we can store it anyway.
This is a weak object pointer.
So because our variable is a new property, it's not a weak object pointer, which means that it affects
reference counting for the player controller.
But our player controller should be persistent.
So we're going to say if we'll go ahead and check current actor info.
And we'll set our player controller variable.
Owner.
Player.
Controller.
Equal to current actor info player controller.
And because this is a weak object pointer, we'll need to call get on it.
And now we'll have our owner player controller.
And these are exposed to blueprint.
So we can go ahead and store this information.
Let's go ahead and run in debug mode.
And we can get that ability back open.
And as soon as we have valid data, I'd like to store that mouse info.
So I'm going to say store mouse data info.
And this takes in a hit result.
So we don't even need to break the hit result anymore.
We can just pass this straight in.
As soon as we have valid data, that's fine.
And we also have.
Store owner.
Player.
Controller.
And this function doesn't need to have anything passed in.
It's just going to get the player controller from the current actor info.
Okay, so as soon as that stuff is done, we can do a number of things here.
The first of which I'd like to do is to hide the mouse cursor.
So as soon as we have valid data here, we're going to do some additional things here.
So we can consider this to be sort of the setup of our ability first and foremost.
We get that data from the mouse cursor and then we can start doing things.
I'm going to make a sequence note here.
And the first thing I'd like to do is hide the mouse cursor by getting our owner player controller.
And setting the show mouse cursor.
Boolean.
I'd like to set it to false.
So I'm going to do that first.
And we'll do a number of other things, but that's number one.
And we'll also wait for the input to be released.
And as soon as we do have a release, we can show that mouse cursor again.
So we can take these nodes and we can paste them and hook them up to on release and show that mouse
cursor here.
Now just so we can activate this multiple times.
I'm going to go ahead and end the ability here.
And the result of this is that, well, we should see our mouse cursor go away and come back when we
let up on that input.
And we can test that by right clicking.
There goes the mouse and un clicking and it comes back right.
So pretty simple but a pretty important step for this gameplay ability.
And of course, we're ending the ability every time that mouse cursor comes back.
So we have a couple of stages here.
The first is very crucial.
We're going to wrap this in a comment that says store target data.
Or we'll say store mouse data variables.
And I'm going to go ahead and give this comment a different color.
So we can make this a little bit more on the pinkish side.
Something like that.
We can even store that color like so.
Actually, that pink is kind of bugging me, so I'm going to change it to more of.
More of a purple.
Yeah.
There we go.
We'll store that one and take that salmon color and bring it out.
We can drag it onto the trashcan there.
Okay.
So we're storing the mouse data variables, hiding the mouse cursor and then on release showing the
mouse cursor.
Now in addition to hiding the mouse cursor, we're going to want to play a montage.
Right.
And the electrocute ability needs a electrocute montage to play.
Now we could make an interface function and keep the electrocute montage on the character.
If we do that, then all characters will have an electrocute montage.
And at that point in a large project, you might start thinking about specializing your character classes
and perhaps even having an interface per character class like you would have an Elementalist interface.
For example, if you had an Elementalist interface, then it could have a function for retrieving an
electrocute montage.
So that's something to keep in mind.
Another option, if you don't want to go through all that trouble, is to have a variable on the electrocute
gameplay ability for the montage, and then if you derive a child of the electrocute gameplay ability
for a different enemy, you can then set that parameter.
And that makes it a little bit more flexible.
So we can make a variable here called electrocute montage.
I'm actually going to call it montage, underscore, electrocute.
And this can be an anim montage.
And we'll make it a object reference.
We'll compile it and we can just set it here.
And that means we'll need to create a montage for aura.
So we'll get to that.
I'm going to go ahead and save everything.
I think this is a good stopping point.
We now have an ability that shows and hides the mouse cursor.
And we're going to soon play that montage.
In the next video, we'll make the montage and get to play in it.
All right.
Great job.
I'll see you soon.