Welcome back.
As you can see, my boring checkered floor has been replaced with my more exciting tiled floor.
And when I press play, it looks a lot better.
Although I do feel like my character's spring arm is a little short, so I might just go into my character
ora ora character and bring that spring arm out just a bit.
Looks like my target arm length is in the four hundreds.
I'm going to bring it up to 7 or 800 or so.
That's a little bit more appropriate for a top down, I think.
And we're good to go.
Now in this video, we're concerned with making a new ability and I'd like a projectile spell.
So we're going to make one of those.
Let's go into C plus plus classes or aura, public ability system and abilities.
Now we are planning on spawning fireballs, but this C plus plus class is not going to be specific to
fire.
This is going to be a projectile spell.
It could be used for fireballs.
It could be used for any kind of projectile.
So I'm not going to put it in a fire folder or anything like that.
I'm just going to put it right here in abilities.
So we'll go ahead and make a new C plus plus class here.
Choose all classes and for this we're going to choose aura gameplay ability because we want to use our
project wide base ability class and that way it'll inherit anything that all of our abilities need,
such as the startup input tag and so on.
So we're going to go ahead and create that class.
I'm going to call this aura projectile spell.
Let's go ahead and create the class.
I'm going to close the editor.
And let's see what we get in our ability system Abilities folder.
We have Aura projectile spell.
So here's the H file.
I'm going to drag it over.
I'm going to open the CPP file and we've got them open here and that's great.
So what does our projectile spell C plus plus class need?
Well, for one, we're going to want to spawn a projectile and we'll get to that.
But what does the gameplay ability class have?
We know that the Blueprint has an Activate event, right?
Well, if we go into aura gameplay ability and right click on new gameplay ability and go to declaration
or usages, here's the gameplay ability class.
Now I highly recommend that you skim through this class just like you did hopefully for the ability
system component.
So if you're so inclined and I do recommend it, pause the video here and go through this whole header
file and read the comments and skim the names of the functions and variables just so you kind of get
an idea of all that the gameplay ability class has and is capable of.
So you don't have to do it, but I highly recommend it.
So go ahead and pause the video now and skim through the class.
Okay.
So hopefully you paused the video and you read through game ability.
And if you did and I think I know you did, then you now know more about gameplay abilities than most
people out there using gas.
It's true.
Just going through and reading these comments will be very enlightening and is probably opened your
eyes to a lot of the things that a gameplay ability can do.
Now you've probably noticed as you were going through that a lot of the comments say that some of these
things are only for instanced abilities, so you're already seeing the limitations of non instanced
abilities.
They can't do certain things right?
And that just comes down to them not being instanced and not able to store any state inside of them.
Now you've seen that there are a lot of functions, but they all seem to center around this activate
ability right?
Activate ability seems to be the most important out of this entire thing, which I'm sure you have noticed.
And if we search for activate ability and we see that there are lots of functions related to it, such
as can activate ability and so on.
But if we keep searching until we find the actual activate ability function, there's a nice big comment
that says this is the main function that defines what an ability does.
Now there are two versions of many of these functions, and you may have noticed that these two versions
are all new functions.
They're all exposed to Blueprint.
K2 is a sort of legacy convention that a lot of engine classes will have in front of their functions
if they're exposed to blueprint.
You see, before Blueprint there used to be kismet and there was a kismet too.
So Kismet version two and then Blueprint came around.
So now we have Blueprint.
So you can kind of think of K2 as Blueprint BP, Right?
K2 is just a legacy convention and you'll see it throughout gas and other engine classes.
So that's just what K2 means.
It's the K2 version or the blueprint version of various functions that exist, and they are often separated
into the native version, which is just C plus plus.
There's no new function.
It's not exposed to reflection or blueprint.
And then the K2 version, which is usually either a blueprint, implementable event, blueprint, callable
blueprint, pure and so on.
So Activate Ability has a native version and as we can see, it's virtual.
And then there's the void K2 Activate ability, which is a blueprint implementable event.
And that means it's an event and the event graph.
Right now, if you're confused, why didn't we see K2 on the event?
Well, that's because the function macro has this display name that says activate ability.
That's what the display name will be in Blueprint.
So that's just one of those you function specifiers that you can use.
Now, there are other associated functions related to activate ability, but activate ability is the
one that we want to override and we don't actually call activate ability.
That is not how we activate abilities.
We activate them by trying to activate them, right?
Because there are things that can prevent them from being activated, such as blocked tags and so on.
So we're concerned with overriding activate ability.
And if we do that in our own custom gameplay ability, then we can determine what happens when that
ability is activated.
So I'd like to override activate ability in or a projectile spell.
Now what is this, a protected function?
Public function?
Well, writer says right here it's a protected method.
So we're going to create a protected section right here in Aura projectile spell.
And we're going to override this virtual function, virtual void, activate ability.
And it has a kind of a long signature.
It's not that long.
It has a gameplay ability spec handle.
So we have access to the spec handle itself.
We've seen how useful spec handles are and in debug mode we've seen that we can dig deep into these
types to find that they often have these pointers right for the data underneath the handle.
The handle is just a lightweight thing we pass around just like a pointer.
We have the gameplay ability actor info and if you read through gameplay ability you'll see that the
comment says that this contains lots of useful information pertaining to the ability.
It's owner controller, lots of different things, so it's got the actor info in it.
We have activation info again, another struct filled with lots of stuff and we can always peek those
structs to see the member variables in them.
But we'll get plenty of experience using these.
Don't worry.
And then there's gameplay event data.
If this ability was activated because of an event and I know that doesn't make any sense to you just
yet, but we have that data and we're going to learn how to activate abilities with gameplay events
as well.
So don't worry if that makes zero sense.
It will when we get to that.
Gas is big, right?
Gas is a huge system.
There's a lot of things to take in.
So that's why I think it's a good idea to just skim right, to just take a look at this whole thing
and don't really dig deep into any one thing, but just notice all the things that are here.
There really aren't that many of them.
So we have activate ability and we're going to go ahead and generate the definition.
We're going to let it call super.
And what are we going to do?
Let's well, why don't we just print a debug message?
So I'm going to add a debug message, but rather than the add on screen debug message function, I'm
so fond of, I'm instead going to use you kismet system library.
Print string.
Why?
Because this is actually the print string that we use in the event graph in blueprints.
This is that print string.
And if we're using the same one then we can see which of these is printed first as they're all going
to use the same function.
And we'll see, based on the order of messages printed to the screen, which of these is called first?
So for print string and by the way, you have to include kismet system library.
For this we can pass in a world context object.
This will do and an F string.
And I'm just going to say activate ability and parentheses C plus plus.
Now for the next argument, be print to screen.
We want that to be true.
We do want to print this to the screen.
Do we want to print it to the log?
Sure.
Let's print it to the log as well.
And linear color is the color and we can use any color we want.
How about yellow?
And for the duration we'll just use three and we'll leave the key name at none.
So that way we'll see all the messages older and newer, and we can create a blueprint from this and
activate the ability and see what happens.
And from here in the editor, I want to create a blueprint based on this.
I'm just going to click open just to see what I had open I had or a character and firebolt That's perfect.
I'll keep those open and let's make a blueprint based on our new gameplay ability.
I'm going to go into blueprints, ability system, gameplay abilities, fire and Firebolt.
I know it's kind of a long path name, but this keeps us organized.
Now I'm going to make a blueprint based on my new Aura projectile spell, so I'm going to search for
or projectile spell.
Select that and call this a for gameplay ability and this can be firebolt.
So we have a new aura projectile spell called Firebolt and we usually prefix them with a as I think
I mentioned before, for gameplay ability.
Now here's our event activate ability and we know that we have activate ability in C plus plus as well.
And from right here in the blueprint I'd like to print a string and for this one I'll go ahead and give
it a duration of three seconds and we'll say activate ability and parentheses Blueprint.
And there we go.
And if we go back to class defaults and take a look at input.
Let's give this a startup input tag of lab for left mouse button.
And that way we can give this ability to our character and we can left click to activate it.
I'd like to see what happens.
So I'm going to compile and save and go to Aura character and search for abilities.
Here's my startup abilities.
I'm going to go ahead and remove that test gameplay ability and add my new game Firebolt ability.
So we should start with that ability.
And we know that because we set its startup input tag to LMB that we should be able to activate it with
the left mouse button.
And if we activate the ability by clicking on an enemy, we have both messages, the blueprint one there
and after that the yellow C plus plus version, which is called after as newer messages are on top.
Great.
So that proves to us that we have both the blueprint and C plus plus version running, but we want to
do more interesting things.
We want to actually spawn projectiles.
So in the next video, we're going to be concerned with doing that.
So this ability is about to get a lot more dangerous.
I'll see you soon.