WEBVTT

00:06.810 --> 00:08.010
Welcome back.

00:08.280 --> 00:14.760
So we've taken a look at the gameplay effect context struct.

00:14.790 --> 00:21.150
We've seen that it exists here in gameplay effect types and we've seen the benefits and the limitations

00:21.150 --> 00:21.910
of it.

00:21.930 --> 00:28.800
And I'd like to create a custom gameplay effect context struct derived from this one.

00:28.950 --> 00:37.380
And that way we can add additional fields to this struct that we may wish to set on the effect context

00:37.380 --> 00:42.420
and pass through and perhaps change and manipulate based on situations.

00:42.420 --> 00:48.930
I'd like to have specifically a couple of booleans in here for whether or not we've gotten a block or

00:48.930 --> 00:49.980
a critical hit.

00:50.670 --> 00:57.390
So since I'm going to be creating my own gameplay effect context struct, I'd like to create it in a

00:57.390 --> 01:03.420
new header file and because I may be creating more of my own types for the ability system, I'm going

01:03.420 --> 01:10.440
to store them in a header file here in the public section and I'm going to create that header file here.

01:10.440 --> 01:15.090
I'm going to right click on my public folder, go to add and select file.

01:15.090 --> 01:19.410
And this is going to be for my ability system custom types.

01:19.410 --> 01:24.060
So I'm going to call this aura ability types.

01:25.160 --> 01:30.930
It could be ability system types, but I'm going to keep the name a little bit shorter and call it aura.

01:30.950 --> 01:32.930
Ability types Dot H.

01:33.020 --> 01:34.310
I'm going to click okay.

01:34.310 --> 01:38.390
And Ryder asks if I'd like to add this to Jet.

01:38.420 --> 01:44.330
I'm going to click Don't Ask again and cancel because I prefer to add these things by myself through

01:44.330 --> 01:45.020
the git bash.

01:45.020 --> 01:52.970
So I'm going to hit cancel and now I have aura ability types, dot h and I'm going to be creating definitions

01:52.970 --> 01:57.830
for functions on my types and I'd like those to be in their CPP file.

01:57.830 --> 02:05.810
So I'm going to right click on the private folder, go to add and select file and this will be Aura

02:05.840 --> 02:08.270
ability types dot CPP.

02:09.050 --> 02:15.620
I'm going to click okay here and the first thing I'm going to do in Aura ability types, CPP is include

02:15.620 --> 02:17.030
that header file.

02:17.030 --> 02:21.590
So I'm going to include aura ability types dot h here.

02:21.950 --> 02:29.520
Now here in aura ability types, I'm going to declare a new struct and this will be derived from the

02:29.730 --> 02:31.890
gameplay effect context struct.

02:31.890 --> 02:40.980
So I'm going to say struct and I'm going to call this f aura gameplay effect context and it's going

02:40.980 --> 02:46.410
to be publicly derived from F gameplay effect context.

02:46.440 --> 02:54.000
That of course means I need to include the header file for gameplay effect context and writer just went

02:54.000 --> 02:55.740
ahead and did it for me.

02:55.740 --> 02:57.900
It included gameplay effect types.

02:57.900 --> 02:59.040
Dot h.

02:59.220 --> 03:03.630
That's where gameplay effect context is defined.

03:04.050 --> 03:09.120
Now writers telling me that the public for a struct is redundant, right?

03:09.120 --> 03:11.220
This is the behavior we get with a struct.

03:11.220 --> 03:13.440
Anyway, I'm going to leave it there.

03:13.530 --> 03:19.320
I'm also going to make this a use struct with blueprint type and give it a generated body.

03:21.580 --> 03:25.030
And I'm going to have multiple access levels.

03:25.030 --> 03:31.420
So I'm going to stick a public right here, even though I know that structs have a public body by default.

03:32.020 --> 03:37.350
I'm going to have a public section labeled there and a protected section.

03:37.360 --> 03:40.120
And again, the public here is redundant.

03:40.360 --> 03:44.860
Even if I add variables and functions here, they would be public anyway.

03:44.860 --> 03:48.760
So this is just because I want this to say public.

03:49.150 --> 03:53.710
Okay, so we've created an aura gameplay effect context struct.

03:53.740 --> 03:57.640
Now we can't just use this struct just because we've created one.

03:57.670 --> 04:02.920
There are a number of steps to go through before we can actually use this and we're actually going to

04:02.920 --> 04:09.640
need to set the gameplay effect context used by our project to this particular struct and we'll get

04:09.640 --> 04:10.720
to that later.

04:10.720 --> 04:19.360
But for now I'd just like to add a couple of things to the struct and before we even add our new booleans,

04:19.360 --> 04:25.180
the whole reason why we wanted these, there are a couple of things that we need before we can get started

04:25.180 --> 04:30.910
on that and we can learn what those things are by looking at the gameplay effect, context, struct

04:30.910 --> 04:32.600
and gameplay effect types.

04:32.600 --> 04:38.690
So here in gameplay effect types, there are just a couple of things that our gameplay effect context

04:38.720 --> 04:39.920
needs to have.

04:39.920 --> 04:47.450
And if we scroll down towards the bottom of this struct we'll come across a function called get script

04:47.450 --> 04:48.320
struct.

04:48.440 --> 04:50.210
Now what is a script struct?

04:50.210 --> 04:56.810
Well, if you're familiar with the static class function on most you objects, you'll know that it returns

04:56.840 --> 04:57.860
a new class.

04:57.890 --> 05:05.030
Now, if you don't know what a class is, it's generated for each class in the engine that's derived

05:05.030 --> 05:08.300
from a new object for the reflection system.

05:08.300 --> 05:16.190
So if you have a new actor class, for example, a new class is generated for that for the reflection

05:16.190 --> 05:19.700
system structs also have a version of this.

05:19.730 --> 05:21.410
It's called a script struct.

05:21.440 --> 05:28.580
So when you create a struct that's capable of being exposed to the reflection system, a script struct

05:28.610 --> 05:31.340
is created for the reflection system.

05:31.340 --> 05:38.540
Think of it as a reflection of that struct, much like a class is a reflection of the object.

05:38.570 --> 05:46.580
Now static struct is a function just like static class that returns that and our gameplay effect context

05:46.610 --> 05:48.680
has a virtual function.

05:48.680 --> 05:53.090
Get script struct which just returns that static struct.

05:53.090 --> 05:57.080
As you can see it just calls static struct and returns that.

05:57.080 --> 06:01.850
And notice the comment says subclasses must override this so we can override it.

06:01.850 --> 06:02.990
I'm going to go ahead and copy it.

06:02.990 --> 06:10.550
This is in the public section here, so we're just going to override it and stick it in our public section

06:10.550 --> 06:12.920
and aura ability types dot h.

06:13.160 --> 06:19.010
And it looks like I actually defined my class in the CPP file.

06:19.010 --> 06:24.980
You might have noticed that I actually meant for this to be in the header file, but that's okay.

06:24.980 --> 06:29.780
I can just cut it and I can stick it right here in the header file.

06:29.780 --> 06:30.920
No big deal.

06:31.010 --> 06:35.900
And in the public section we're going to override get script struct.

06:35.900 --> 06:40.580
So I'm going to copy these lines here and just paste them here in the public section.

06:41.390 --> 06:41.870
Okay.

06:41.870 --> 06:44.750
So that's one thing that we need.

06:44.780 --> 06:47.720
Let's go back and take a look at what else we have.

06:47.720 --> 06:53.750
We're going to scroll down and there's a very important function at the end of the public section called

06:53.750 --> 06:55.040
Net Serialize.

06:55.040 --> 07:00.350
And the comment says custom serialization subclasses must override this.

07:00.560 --> 07:05.510
Now, net Serialize determines how this struct is serialized.

07:05.690 --> 07:12.920
Now serialization is necessary if you're going to save one of these structs, for example, or send

07:12.920 --> 07:14.480
it across the network.

07:14.780 --> 07:18.200
These are things that require serialization.

07:18.200 --> 07:25.460
In other words, take a struct, convert it into bits, zeros and ones and send those bits in a stream

07:25.460 --> 07:26.780
across the internet.

07:26.810 --> 07:31.780
If you want to be able to replicate something, it needs this net serialize.

07:31.790 --> 07:33.350
Interesting, right?

07:33.350 --> 07:39.260
So we're going to learn all about this in the next few videos, but for now we're just going to override

07:39.260 --> 07:40.400
it as we have to.

07:40.400 --> 07:44.600
So we're going to go to aura ability types and override net serialize.

07:44.630 --> 07:46.340
I'll go ahead and.

07:46.950 --> 07:49.110
Generate a definition for it.

07:49.290 --> 07:51.010
I'm going to empty it out.

07:51.030 --> 07:54.270
So we're going to need to return something from this.

07:54.780 --> 07:56.940
For now, I'm just going to return.

07:56.940 --> 07:59.670
True until we fill this out.

07:59.670 --> 08:01.470
But we do need to fill this out.

08:01.800 --> 08:03.680
And what are we going to fill it out with?

08:03.690 --> 08:09.720
Well, we need to specify how our struct is going to be serialized, which means we have to learn about

08:09.720 --> 08:10.750
how that works.

08:10.770 --> 08:17.940
Now we can learn about how that works by seeing the definition for net serialize for the gameplay effect

08:17.940 --> 08:18.950
context.

08:18.960 --> 08:27.000
So I can go to gameplay effect types dot CP and search for gameplay effect context net serialized function

08:27.000 --> 08:27.570
here.

08:27.780 --> 08:34.290
And if you take a look at net serialize for the first time it's going to look quite cryptic.

08:34.320 --> 08:37.440
There are some things in here that look a lot like magic.

08:37.530 --> 08:42.390
So for that reason we're going to need to have a discussion about this.

08:42.480 --> 08:45.450
Notice that net Serialize takes three inputs.

08:45.550 --> 08:52.210
One is an archive passed in by reference and it's not a const reference, so that should tip you off

08:52.210 --> 08:54.070
about this input parameter.

08:54.070 --> 09:01.300
It should tell you, well, maybe this function is designed to fill it in somehow to change this f archive

09:01.330 --> 09:03.100
mystical object here.

09:03.580 --> 09:09.910
There's also a u package map called map passed in and a boolean called B out Success.

09:10.210 --> 09:12.790
Now let's take a look at what's happening here.

09:12.820 --> 09:19.990
Notice that we're performing some if checks and all of these if checks, every single one of them has

09:19.990 --> 09:24.670
to do with one of the variables stored on this gameplay effect.

09:24.670 --> 09:29.980
Context struct notice we have the actors, we have the hit results has world origin.

09:29.980 --> 09:30.640
Right?

09:30.640 --> 09:34.450
So it's checking something about these, right?

09:34.450 --> 09:38.950
It's looking at if instigator is valid, if effect causer is valid.

09:38.950 --> 09:44.050
So it's checking things and then it's doing something that looks a little bit strange.

09:44.320 --> 09:48.220
And all of this is in an if r dot is saving.

09:48.220 --> 09:52.240
So this F archive has a dot is saving, right?

09:52.240 --> 09:53.830
This is saving function.

09:53.830 --> 10:01.480
Then we call a function called serialized bits on it and then have another series of if statements checking

10:01.480 --> 10:08.980
another sort of cryptic expression here before doing something with the R, this archive object.

10:09.160 --> 10:14.500
And it looks like each of these has to do with the variables here in the struct again.

10:14.500 --> 10:21.580
So at a high level, in a nutshell, net serialize is just serializing each of the member variables

10:21.580 --> 10:28.120
in this struct, saving it into an archive if the struct is being saved.

10:28.120 --> 10:33.820
But if the struct is not being saved, if it's being loaded, well then we're getting that data out

10:33.820 --> 10:35.020
of the archive.

10:35.260 --> 10:36.280
Kind of confusing.

10:36.280 --> 10:36.640
Right?

10:36.640 --> 10:39.280
So we're going to talk about this in the next video.

10:39.280 --> 10:45.340
For now, it's enough to know at a high level what this net serialized does and that we need to override

10:45.340 --> 10:45.820
it.

10:45.820 --> 10:50.320
But how are we going to override it when we don't know what's going on here?

10:50.320 --> 10:57.940
And especially if we're going to have even more variables here that don't exist in gameplay effect context.

10:58.090 --> 11:01.450
So in the next video, we'll learn about how Net Serialize works.

11:01.450 --> 11:07.960
But before we wrap up, let's go ahead and add those variables that we'd like on our custom gameplay

11:07.960 --> 11:09.310
effect context.

11:09.310 --> 11:11.170
So I'm going to add those.

11:11.200 --> 11:14.710
They're going to be protected and they're just going to be balls.

11:14.710 --> 11:23.860
There's going to be one bool called B is critical hit and it'll be set to false by default and we're

11:23.860 --> 11:27.760
going to give it a new property and I'm going to have another one.

11:27.790 --> 11:31.270
B is block or is blocked hit.

11:31.270 --> 11:33.130
I'd like that one to be first, actually.

11:33.130 --> 11:35.320
So B is blocked.

11:35.350 --> 11:36.700
Hit equals false.

11:36.700 --> 11:38.890
We have both of these and they're protected.

11:39.010 --> 11:45.880
Now, I'd like to create functions to retrieve these that are public so that we can get them from outside

11:45.880 --> 11:50.290
the class and functions to set them basically getters and setters.

11:50.440 --> 11:59.680
So up here in the public section I'm going to make a bool is critical hit const function that returns

11:59.710 --> 12:02.320
B is critical hit.

12:03.330 --> 12:07.470
And I'll make a bool is blocked hit.

12:09.680 --> 12:13.950
Also const that returns B is blocked.

12:13.970 --> 12:14.540
Hit.

12:15.230 --> 12:17.630
And then I'll make a void.

12:17.630 --> 12:28.430
Function called set is critical hit, which takes a bool called B in is critical hit.

12:30.100 --> 12:31.960
And sets B is critical.

12:31.960 --> 12:37.060
Hit equal to b n is critical hit simple.

12:37.240 --> 12:44.230
And we'll have another one for is blocked hit so void and this will be set is blocked hit.

12:45.570 --> 12:49.800
It'll take a bull called B in is blocked hit.

12:51.630 --> 12:58.740
And it's going to set B is blocked, hit equal to B in is blocked, hit.

12:58.950 --> 12:59.670
Cool.

12:59.670 --> 13:07.530
So we have our new variables justifying going through all this trouble to make our own effect context.

13:07.530 --> 13:12.510
But the only problem is we don't have net serialize filled out.

13:12.510 --> 13:15.480
This function needs to be filled out.

13:15.510 --> 13:24.150
And one last very important detail before we give this a test compile is we have a generated body here.

13:24.150 --> 13:28.260
That means we need a generated h file for this header file.

13:28.260 --> 13:37.680
And in fact, another safeguard is to use pragma once at the top so this header can't be included more

13:37.680 --> 13:38.970
than once anywhere.

13:39.180 --> 13:45.420
So we got pragma once and we're also going to include all the ability types.

13:47.570 --> 13:50.630
Dot generated Dot h.

13:52.210 --> 13:53.920
Now I'm going to compile this.

13:56.140 --> 13:59.100
And with that, we have a successful compile.

13:59.110 --> 14:01.210
Everything's looking good so far.

14:01.240 --> 14:02.830
The next step is to fill out.

14:02.860 --> 14:07.930
Net serialize and that involves learning how the gameplay effect context.

14:07.960 --> 14:12.700
Net serialize class works and that's in gameplay effect type scope.

14:12.970 --> 14:18.880
So in the next video we're going to discuss this and demystify it so that we can put this type of thing

14:18.910 --> 14:21.550
to use in our gameplay effect context.

14:21.550 --> 14:22.910
And we'll do that next.

14:22.930 --> 14:24.100
I'll see you soon.
