WEBVTT

00:06.990 --> 00:08.220
Welcome back.

00:08.340 --> 00:16.350
As you can see, my boring checkered floor has been replaced with my more exciting tiled floor.

00:16.350 --> 00:19.500
And when I press play, it looks a lot better.

00:19.500 --> 00:28.770
Although I do feel like my character's spring arm is a little short, so I might just go into my character

00:28.770 --> 00:35.040
ora ora character and bring that spring arm out just a bit.

00:35.140 --> 00:38.060
Looks like my target arm length is in the four hundreds.

00:38.070 --> 00:40.740
I'm going to bring it up to 7 or 800 or so.

00:42.110 --> 00:45.170
That's a little bit more appropriate for a top down, I think.

00:45.260 --> 00:47.650
And we're good to go.

00:47.660 --> 00:55.400
Now in this video, we're concerned with making a new ability and I'd like a projectile spell.

00:55.520 --> 00:57.500
So we're going to make one of those.

00:57.530 --> 01:04.490
Let's go into C plus plus classes or aura, public ability system and abilities.

01:04.520 --> 01:12.440
Now we are planning on spawning fireballs, but this C plus plus class is not going to be specific to

01:12.440 --> 01:13.130
fire.

01:13.160 --> 01:16.010
This is going to be a projectile spell.

01:16.010 --> 01:17.480
It could be used for fireballs.

01:17.480 --> 01:20.410
It could be used for any kind of projectile.

01:20.420 --> 01:24.380
So I'm not going to put it in a fire folder or anything like that.

01:24.380 --> 01:26.870
I'm just going to put it right here in abilities.

01:26.870 --> 01:30.560
So we'll go ahead and make a new C plus plus class here.

01:30.560 --> 01:39.710
Choose all classes and for this we're going to choose aura gameplay ability because we want to use our

01:39.710 --> 01:47.880
project wide base ability class and that way it'll inherit anything that all of our abilities need,

01:47.880 --> 01:50.820
such as the startup input tag and so on.

01:50.820 --> 01:54.090
So we're going to go ahead and create that class.

01:54.090 --> 01:59.820
I'm going to call this aura projectile spell.

01:59.850 --> 02:01.620
Let's go ahead and create the class.

02:01.620 --> 02:03.270
I'm going to close the editor.

02:04.040 --> 02:10.190
And let's see what we get in our ability system Abilities folder.

02:10.190 --> 02:12.500
We have Aura projectile spell.

02:12.500 --> 02:14.750
So here's the H file.

02:14.750 --> 02:16.310
I'm going to drag it over.

02:16.310 --> 02:22.450
I'm going to open the CPP file and we've got them open here and that's great.

02:22.460 --> 02:26.900
So what does our projectile spell C plus plus class need?

02:26.900 --> 02:30.920
Well, for one, we're going to want to spawn a projectile and we'll get to that.

02:30.920 --> 02:34.340
But what does the gameplay ability class have?

02:34.340 --> 02:37.760
We know that the Blueprint has an Activate event, right?

02:37.790 --> 02:45.500
Well, if we go into aura gameplay ability and right click on new gameplay ability and go to declaration

02:45.500 --> 02:48.950
or usages, here's the gameplay ability class.

02:49.190 --> 02:56.990
Now I highly recommend that you skim through this class just like you did hopefully for the ability

02:56.990 --> 02:58.250
system component.

02:58.280 --> 03:05.940
So if you're so inclined and I do recommend it, pause the video here and go through this whole header

03:05.940 --> 03:13.290
file and read the comments and skim the names of the functions and variables just so you kind of get

03:13.290 --> 03:18.180
an idea of all that the gameplay ability class has and is capable of.

03:18.180 --> 03:21.180
So you don't have to do it, but I highly recommend it.

03:21.180 --> 03:24.990
So go ahead and pause the video now and skim through the class.

03:25.840 --> 03:26.410
Okay.

03:26.410 --> 03:31.270
So hopefully you paused the video and you read through game ability.

03:31.960 --> 03:39.580
And if you did and I think I know you did, then you now know more about gameplay abilities than most

03:39.580 --> 03:41.470
people out there using gas.

03:41.500 --> 03:42.520
It's true.

03:42.550 --> 03:48.400
Just going through and reading these comments will be very enlightening and is probably opened your

03:48.400 --> 03:52.180
eyes to a lot of the things that a gameplay ability can do.

03:52.210 --> 03:57.700
Now you've probably noticed as you were going through that a lot of the comments say that some of these

03:57.700 --> 04:04.660
things are only for instanced abilities, so you're already seeing the limitations of non instanced

04:04.660 --> 04:05.170
abilities.

04:05.170 --> 04:07.270
They can't do certain things right?

04:07.270 --> 04:15.150
And that just comes down to them not being instanced and not able to store any state inside of them.

04:15.160 --> 04:24.250
Now you've seen that there are a lot of functions, but they all seem to center around this activate

04:24.280 --> 04:25.700
ability right?

04:25.700 --> 04:33.410
Activate ability seems to be the most important out of this entire thing, which I'm sure you have noticed.

04:33.410 --> 04:41.240
And if we search for activate ability and we see that there are lots of functions related to it, such

04:41.240 --> 04:43.340
as can activate ability and so on.

04:43.340 --> 04:50.900
But if we keep searching until we find the actual activate ability function, there's a nice big comment

04:50.900 --> 04:54.920
that says this is the main function that defines what an ability does.

04:55.130 --> 05:02.090
Now there are two versions of many of these functions, and you may have noticed that these two versions

05:02.120 --> 05:03.890
are all new functions.

05:03.910 --> 05:05.870
They're all exposed to Blueprint.

05:05.960 --> 05:13.070
K2 is a sort of legacy convention that a lot of engine classes will have in front of their functions

05:13.070 --> 05:15.050
if they're exposed to blueprint.

05:15.080 --> 05:20.620
You see, before Blueprint there used to be kismet and there was a kismet too.

05:20.630 --> 05:25.130
So Kismet version two and then Blueprint came around.

05:25.130 --> 05:26.450
So now we have Blueprint.

05:26.450 --> 05:32.630
So you can kind of think of K2 as Blueprint BP, Right?

05:32.780 --> 05:38.900
K2 is just a legacy convention and you'll see it throughout gas and other engine classes.

05:38.900 --> 05:41.270
So that's just what K2 means.

05:41.270 --> 05:49.250
It's the K2 version or the blueprint version of various functions that exist, and they are often separated

05:49.250 --> 05:52.520
into the native version, which is just C plus plus.

05:52.520 --> 05:53.750
There's no new function.

05:53.750 --> 05:56.510
It's not exposed to reflection or blueprint.

05:56.510 --> 06:02.030
And then the K2 version, which is usually either a blueprint, implementable event, blueprint, callable

06:02.060 --> 06:03.770
blueprint, pure and so on.

06:03.980 --> 06:09.290
So Activate Ability has a native version and as we can see, it's virtual.

06:09.290 --> 06:15.890
And then there's the void K2 Activate ability, which is a blueprint implementable event.

06:15.890 --> 06:18.770
And that means it's an event and the event graph.

06:18.770 --> 06:23.690
Right now, if you're confused, why didn't we see K2 on the event?

06:23.720 --> 06:29.860
Well, that's because the function macro has this display name that says activate ability.

06:29.860 --> 06:32.560
That's what the display name will be in Blueprint.

06:32.560 --> 06:37.390
So that's just one of those you function specifiers that you can use.

06:37.420 --> 06:43.750
Now, there are other associated functions related to activate ability, but activate ability is the

06:43.750 --> 06:49.240
one that we want to override and we don't actually call activate ability.

06:49.240 --> 06:51.520
That is not how we activate abilities.

06:51.520 --> 06:54.730
We activate them by trying to activate them, right?

06:54.730 --> 07:00.160
Because there are things that can prevent them from being activated, such as blocked tags and so on.

07:00.160 --> 07:04.300
So we're concerned with overriding activate ability.

07:04.300 --> 07:10.090
And if we do that in our own custom gameplay ability, then we can determine what happens when that

07:10.090 --> 07:11.950
ability is activated.

07:11.950 --> 07:17.050
So I'd like to override activate ability in or a projectile spell.

07:17.080 --> 07:19.930
Now what is this, a protected function?

07:19.930 --> 07:20.890
Public function?

07:20.890 --> 07:23.710
Well, writer says right here it's a protected method.

07:23.710 --> 07:29.540
So we're going to create a protected section right here in Aura projectile spell.

07:30.760 --> 07:36.190
And we're going to override this virtual function, virtual void, activate ability.

07:36.280 --> 07:38.740
And it has a kind of a long signature.

07:38.740 --> 07:39.940
It's not that long.

07:39.950 --> 07:43.240
It has a gameplay ability spec handle.

07:43.240 --> 07:46.030
So we have access to the spec handle itself.

07:46.030 --> 07:52.450
We've seen how useful spec handles are and in debug mode we've seen that we can dig deep into these

07:52.450 --> 08:00.010
types to find that they often have these pointers right for the data underneath the handle.

08:00.010 --> 08:04.000
The handle is just a lightweight thing we pass around just like a pointer.

08:04.000 --> 08:10.090
We have the gameplay ability actor info and if you read through gameplay ability you'll see that the

08:10.090 --> 08:15.010
comment says that this contains lots of useful information pertaining to the ability.

08:15.010 --> 08:20.470
It's owner controller, lots of different things, so it's got the actor info in it.

08:20.500 --> 08:26.800
We have activation info again, another struct filled with lots of stuff and we can always peek those

08:26.800 --> 08:29.200
structs to see the member variables in them.

08:29.200 --> 08:31.880
But we'll get plenty of experience using these.

08:31.880 --> 08:32.720
Don't worry.

08:32.720 --> 08:34.940
And then there's gameplay event data.

08:34.940 --> 08:41.630
If this ability was activated because of an event and I know that doesn't make any sense to you just

08:41.630 --> 08:47.870
yet, but we have that data and we're going to learn how to activate abilities with gameplay events

08:47.870 --> 08:48.650
as well.

08:48.650 --> 08:51.080
So don't worry if that makes zero sense.

08:51.110 --> 08:52.850
It will when we get to that.

08:52.850 --> 08:54.020
Gas is big, right?

08:54.020 --> 08:55.610
Gas is a huge system.

08:55.610 --> 08:57.290
There's a lot of things to take in.

08:57.290 --> 09:04.520
So that's why I think it's a good idea to just skim right, to just take a look at this whole thing

09:04.520 --> 09:10.730
and don't really dig deep into any one thing, but just notice all the things that are here.

09:10.820 --> 09:12.530
There really aren't that many of them.

09:12.890 --> 09:17.630
So we have activate ability and we're going to go ahead and generate the definition.

09:17.630 --> 09:19.580
We're going to let it call super.

09:19.580 --> 09:21.200
And what are we going to do?

09:21.200 --> 09:24.650
Let's well, why don't we just print a debug message?

09:24.650 --> 09:30.470
So I'm going to add a debug message, but rather than the add on screen debug message function, I'm

09:30.470 --> 09:35.720
so fond of, I'm instead going to use you kismet system library.

09:36.290 --> 09:37.520
Print string.

09:37.520 --> 09:37.940
Why?

09:37.970 --> 09:43.850
Because this is actually the print string that we use in the event graph in blueprints.

09:43.850 --> 09:46.430
This is that print string.

09:46.430 --> 09:52.250
And if we're using the same one then we can see which of these is printed first as they're all going

09:52.250 --> 09:54.170
to use the same function.

09:54.170 --> 10:00.800
And we'll see, based on the order of messages printed to the screen, which of these is called first?

10:00.800 --> 10:05.420
So for print string and by the way, you have to include kismet system library.

10:05.420 --> 10:08.870
For this we can pass in a world context object.

10:08.870 --> 10:11.420
This will do and an F string.

10:11.420 --> 10:17.630
And I'm just going to say activate ability and parentheses C plus plus.

10:18.480 --> 10:21.240
Now for the next argument, be print to screen.

10:21.240 --> 10:22.650
We want that to be true.

10:22.680 --> 10:24.900
We do want to print this to the screen.

10:24.930 --> 10:26.620
Do we want to print it to the log?

10:26.640 --> 10:27.030
Sure.

10:27.030 --> 10:28.890
Let's print it to the log as well.

10:28.890 --> 10:36.150
And linear color is the color and we can use any color we want.

10:36.300 --> 10:38.520
How about yellow?

10:38.790 --> 10:45.540
And for the duration we'll just use three and we'll leave the key name at none.

10:45.540 --> 10:53.640
So that way we'll see all the messages older and newer, and we can create a blueprint from this and

10:53.640 --> 10:57.090
activate the ability and see what happens.

10:57.360 --> 11:02.130
And from here in the editor, I want to create a blueprint based on this.

11:02.310 --> 11:07.500
I'm just going to click open just to see what I had open I had or a character and firebolt That's perfect.

11:07.500 --> 11:12.210
I'll keep those open and let's make a blueprint based on our new gameplay ability.

11:12.210 --> 11:18.580
I'm going to go into blueprints, ability system, gameplay abilities, fire and Firebolt.

11:18.580 --> 11:23.170
I know it's kind of a long path name, but this keeps us organized.

11:23.200 --> 11:29.260
Now I'm going to make a blueprint based on my new Aura projectile spell, so I'm going to search for

11:29.260 --> 11:31.420
or projectile spell.

11:31.510 --> 11:39.430
Select that and call this a for gameplay ability and this can be firebolt.

11:40.580 --> 11:47.240
So we have a new aura projectile spell called Firebolt and we usually prefix them with a as I think

11:47.240 --> 11:49.760
I mentioned before, for gameplay ability.

11:50.330 --> 11:57.890
Now here's our event activate ability and we know that we have activate ability in C plus plus as well.

11:57.890 --> 12:04.100
And from right here in the blueprint I'd like to print a string and for this one I'll go ahead and give

12:04.100 --> 12:12.110
it a duration of three seconds and we'll say activate ability and parentheses Blueprint.

12:14.280 --> 12:15.660
And there we go.

12:15.810 --> 12:20.920
And if we go back to class defaults and take a look at input.

12:20.940 --> 12:25.380
Let's give this a startup input tag of lab for left mouse button.

12:25.380 --> 12:31.740
And that way we can give this ability to our character and we can left click to activate it.

12:31.740 --> 12:33.270
I'd like to see what happens.

12:33.270 --> 12:39.780
So I'm going to compile and save and go to Aura character and search for abilities.

12:40.490 --> 12:42.390
Here's my startup abilities.

12:42.410 --> 12:50.330
I'm going to go ahead and remove that test gameplay ability and add my new game Firebolt ability.

12:50.330 --> 12:52.430
So we should start with that ability.

12:52.430 --> 12:58.670
And we know that because we set its startup input tag to LMB that we should be able to activate it with

12:58.670 --> 13:00.140
the left mouse button.

13:00.440 --> 13:07.160
And if we activate the ability by clicking on an enemy, we have both messages, the blueprint one there

13:07.160 --> 13:15.950
and after that the yellow C plus plus version, which is called after as newer messages are on top.

13:16.840 --> 13:17.260
Great.

13:17.260 --> 13:23.680
So that proves to us that we have both the blueprint and C plus plus version running, but we want to

13:23.680 --> 13:25.420
do more interesting things.

13:25.420 --> 13:27.960
We want to actually spawn projectiles.

13:27.970 --> 13:31.630
So in the next video, we're going to be concerned with doing that.

13:31.630 --> 13:35.500
So this ability is about to get a lot more dangerous.

13:35.530 --> 13:36.790
I'll see you soon.
