Welcome back.
Now, congratulations on that last lecture because we've now done something a little bit more advanced,
and that's pretty cool.
We now have a way for our new custom context to be serialized.
Our custom effect context has its own net serialize.
Now, that's not the only thing that an effect.
Context needs to be serializable.
There's another important step, and we can see that if we go to gameplay effect types and scroll down
to the bottom of our effect context class.
In fact, just past the bottom of it, we'll see this struct here, which is a template defined.
Now this struct is called t struct ops type traits, but it's not just any struct ops type traits.
It's specified with gameplay effect context.
So this is defining a struct called struct ops type traits for this particular template parameter.
Now this is derived from t struct ops type traits.
Base two and notice we have enum here and each enumerator is set to a true or false value.
That may seem a little bit strange if you've never seen that before, but enums are integers and true
and false can be treated like zeros and ones.
Right?
Now what do these mean and why do we have this here?
Well, these t struct ops type traits defines what can be done with this particular struct f gameplay
effect context.
And these qualities here that are set to true are important for things like serialization and for the
reflection system.
If I right click on t struct ops type traits base two and I go to the declaration or usages, it's going
to take me to class dot h and the comment says type traits to cover the custom aspects of a script struct.
So this has to do with the script struct which is used by the reflection system.
It's also used for other important things like serialization and the struct ops type traits just defines
what that script struct is capable of doing.
And there are quite a few options here and to define what can be done with that script.
Struct you set one of these enum constants to true in order for that script struct to have that capability.
Now you can go through these and read them all if you like, but really we just care about two of them.
The two that are set here in gameplay effect types with net serializer and with copy.
So let's take a look at the comments in class for those two we have with net serializer.
And the comment says struct has a net serialize function for serializing its state to an archive used
for network replication.
So because we wish to do this, we need to set this to true with our struct ops type traits for our
custom struct.
Now we also have the width copy set to true and it says struct can be copied via its copy assignment.
Operator.
So there's that if we'd like that.
And by the way we saw that in game play effect types, there was this nice copy function, it was a
duplicate handling, creating a copy of this context.
If we want this, we could just simply copy, for lack of a better word, and we can paste this into
the public section in our struct so we can put that.
I'm going to put it right above net serialize there.
But what we really need though is our struct ops type traits.
So we declare that down here just below the class, it's a template.
So we're going to say template and we create a new struct called t struct ops type traits and specify
our custom gameplay effect context.
That's for a gameplay effect context we're going to derive from t struct.
Ops type traits.
Base two and we're going to specify for a gameplay effect context.
And if you want, you could place the public here.
But it is redundant as writer will gray it out there.
Now we define enum here and we need to set the enumerators with net serializer.
Equal to true comma and with copy equal to true.
And with that we have our struct ops type traits defined for our custom gameplay effect context.
And that is a subtle yet very important detail that we need if we're going to have our own custom gameplay
effect context.
And with that, our gameplay effect context so far is looking complete.
Now, I've already mentioned in a previous video that we can't just use this.
We can't just expect that our project knows we want to use this class as our gameplay effect context.
So what we'll learn how to do next is to designate the gameplay effect context struct project wide to
be this one that gets used and then we'll learn how to utilize it.
So excellent job and I'll see you soon.
Hey there.
It's Steven from the Future.
And I'm back with just a slight update in Unreal Engine 5.3.
We will actually get an error related to serializing our custom effect context.
Now, the solution is quite simple.
All we really need to do is make sure that our duplicate function here is set to return our custom type.
That is our aura gameplay effect, context or whatever it is that you named.
This particular struct mine is called aura gameplay effect context and the duplicate function should
return a pointer to this type.
So it should have f aura gameplay effect context in it.
Now that also means that our new context local variable must be of this type.
So when we use the new keyword we should use F aura gameplay effect context.
And with this fix now we shouldn't get any problems serializing our custom gameplay effect context if
we duplicate it with this function.
Now, one other minor change is also that we need to return our static struct without fully qualifying
the gameplay effect context.
We don't need to do that.
We can simply return static struct without fully qualifying the name there.
This will not give us any errors when attempting to serialize this particular type.
So just a couple of minor changes that we need in 5.3 and most likely beyond.
So something to keep in mind.
And if you check the repo for this lecture, you will see it still as the old way.
But make sure you do it this new way so that you don't get any errors.