WEBVTT

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

00:07.890 --> 00:13.380
Now, congratulations on that last lecture because we've now done something a little bit more advanced,

00:13.380 --> 00:14.610
and that's pretty cool.

00:14.640 --> 00:19.450
We now have a way for our new custom context to be serialized.

00:19.470 --> 00:23.520
Our custom effect context has its own net serialize.

00:23.880 --> 00:26.820
Now, that's not the only thing that an effect.

00:26.820 --> 00:30.150
Context needs to be serializable.

00:30.180 --> 00:37.530
There's another important step, and we can see that if we go to gameplay effect types and scroll down

00:37.530 --> 00:40.590
to the bottom of our effect context class.

00:40.590 --> 00:47.910
In fact, just past the bottom of it, we'll see this struct here, which is a template defined.

00:48.180 --> 00:56.440
Now this struct is called t struct ops type traits, but it's not just any struct ops type traits.

00:56.460 --> 01:00.780
It's specified with gameplay effect context.

01:00.780 --> 01:08.640
So this is defining a struct called struct ops type traits for this particular template parameter.

01:08.670 --> 01:12.300
Now this is derived from t struct ops type traits.

01:12.300 --> 01:19.800
Base two and notice we have enum here and each enumerator is set to a true or false value.

01:19.830 --> 01:26.430
That may seem a little bit strange if you've never seen that before, but enums are integers and true

01:26.430 --> 01:30.060
and false can be treated like zeros and ones.

01:30.090 --> 01:30.810
Right?

01:31.020 --> 01:34.890
Now what do these mean and why do we have this here?

01:34.920 --> 01:43.980
Well, these t struct ops type traits defines what can be done with this particular struct f gameplay

01:43.980 --> 01:45.420
effect context.

01:45.420 --> 01:53.340
And these qualities here that are set to true are important for things like serialization and for the

01:53.340 --> 01:54.540
reflection system.

01:54.550 --> 02:01.260
If I right click on t struct ops type traits base two and I go to the declaration or usages, it's going

02:01.260 --> 02:08.860
to take me to class dot h and the comment says type traits to cover the custom aspects of a script struct.

02:08.860 --> 02:13.690
So this has to do with the script struct which is used by the reflection system.

02:13.690 --> 02:21.820
It's also used for other important things like serialization and the struct ops type traits just defines

02:21.820 --> 02:24.550
what that script struct is capable of doing.

02:24.670 --> 02:29.890
And there are quite a few options here and to define what can be done with that script.

02:29.890 --> 02:37.510
Struct you set one of these enum constants to true in order for that script struct to have that capability.

02:37.720 --> 02:44.110
Now you can go through these and read them all if you like, but really we just care about two of them.

02:44.110 --> 02:51.250
The two that are set here in gameplay effect types with net serializer and with copy.

02:51.900 --> 02:58.950
So let's take a look at the comments in class for those two we have with net serializer.

02:59.220 --> 03:07.380
And the comment says struct has a net serialize function for serializing its state to an archive used

03:07.380 --> 03:08.820
for network replication.

03:08.820 --> 03:16.320
So because we wish to do this, we need to set this to true with our struct ops type traits for our

03:16.320 --> 03:17.430
custom struct.

03:17.460 --> 03:24.810
Now we also have the width copy set to true and it says struct can be copied via its copy assignment.

03:24.810 --> 03:25.820
Operator.

03:25.830 --> 03:28.440
So there's that if we'd like that.

03:28.440 --> 03:36.150
And by the way we saw that in game play effect types, there was this nice copy function, it was a

03:36.150 --> 03:40.080
duplicate handling, creating a copy of this context.

03:40.080 --> 03:46.170
If we want this, we could just simply copy, for lack of a better word, and we can paste this into

03:46.170 --> 03:50.400
the public section in our struct so we can put that.

03:50.400 --> 03:53.560
I'm going to put it right above net serialize there.

03:53.560 --> 03:58.180
But what we really need though is our struct ops type traits.

03:58.480 --> 04:02.890
So we declare that down here just below the class, it's a template.

04:02.890 --> 04:13.810
So we're going to say template and we create a new struct called t struct ops type traits and specify

04:13.810 --> 04:16.990
our custom gameplay effect context.

04:17.020 --> 04:24.430
That's for a gameplay effect context we're going to derive from t struct.

04:25.590 --> 04:27.240
Ops type traits.

04:27.240 --> 04:33.210
Base two and we're going to specify for a gameplay effect context.

04:33.210 --> 04:35.640
And if you want, you could place the public here.

04:35.640 --> 04:40.810
But it is redundant as writer will gray it out there.

04:40.830 --> 04:50.100
Now we define enum here and we need to set the enumerators with net serializer.

04:52.280 --> 04:58.130
Equal to true comma and with copy equal to true.

04:58.990 --> 05:06.570
And with that we have our struct ops type traits defined for our custom gameplay effect context.

05:06.580 --> 05:13.630
And that is a subtle yet very important detail that we need if we're going to have our own custom gameplay

05:13.630 --> 05:14.920
effect context.

05:14.920 --> 05:21.520
And with that, our gameplay effect context so far is looking complete.

05:22.490 --> 05:26.660
Now, I've already mentioned in a previous video that we can't just use this.

05:26.690 --> 05:33.450
We can't just expect that our project knows we want to use this class as our gameplay effect context.

05:33.470 --> 05:42.470
So what we'll learn how to do next is to designate the gameplay effect context struct project wide to

05:42.470 --> 05:46.700
be this one that gets used and then we'll learn how to utilize it.

05:47.030 --> 05:49.790
So excellent job and I'll see you soon.

05:50.780 --> 05:51.410
Hey there.

05:51.410 --> 05:52.910
It's Steven from the Future.

05:52.910 --> 05:58.010
And I'm back with just a slight update in Unreal Engine 5.3.

05:58.040 --> 06:05.320
We will actually get an error related to serializing our custom effect context.

06:05.330 --> 06:07.520
Now, the solution is quite simple.

06:07.550 --> 06:15.710
All we really need to do is make sure that our duplicate function here is set to return our custom type.

06:15.710 --> 06:22.880
That is our aura gameplay effect, context or whatever it is that you named.

06:22.880 --> 06:30.830
This particular struct mine is called aura gameplay effect context and the duplicate function should

06:30.830 --> 06:33.680
return a pointer to this type.

06:33.680 --> 06:37.910
So it should have f aura gameplay effect context in it.

06:37.910 --> 06:43.790
Now that also means that our new context local variable must be of this type.

06:43.790 --> 06:49.250
So when we use the new keyword we should use F aura gameplay effect context.

06:49.250 --> 06:57.540
And with this fix now we shouldn't get any problems serializing our custom gameplay effect context if

06:57.540 --> 06:59.520
we duplicate it with this function.

06:59.520 --> 07:08.910
Now, one other minor change is also that we need to return our static struct without fully qualifying

07:08.910 --> 07:10.920
the gameplay effect context.

07:10.950 --> 07:12.000
We don't need to do that.

07:12.000 --> 07:18.900
We can simply return static struct without fully qualifying the name there.

07:19.110 --> 07:25.950
This will not give us any errors when attempting to serialize this particular type.

07:25.950 --> 07:32.730
So just a couple of minor changes that we need in 5.3 and most likely beyond.

07:32.730 --> 07:34.620
So something to keep in mind.

07:34.620 --> 07:40.770
And if you check the repo for this lecture, you will see it still as the old way.

07:40.770 --> 07:45.330
But make sure you do it this new way so that you don't get any errors.
