Welcome back.
So we've added a death impulse magnitude to aura damage gameplay ability.
And we're setting that in make damage effect params from class defaults.
So the damage effect params will carry that magnitude along.
But we know that by the time our projectile hits something, we're going to have a direction which is
a vector that we want to pass along, perhaps scaled by that magnitude.
And ultimately, when our attribute set determines that damage was fatal, it can handle using that
vector.
For that reason, I'd like our custom gameplay effect context to have a vector, and that involves several
steps.
If we want to add that to our effect context.
And we're going to handle those in this video and see the differences between a vector and the other
types with our effect context.
So we're going to add an f vector member variable called death impulse.
And it's going to get a new property.
And we're going to set this to the zero vector.
So f vector zero vector we want to make sure it's initialized to zero.
Because if we never set this to anything other than zero there's no point in replicating it.
Speaking of replication, we need to handle this variable and net serialize don't we?
So in aura ability type cp and net serialize we need to handle this.
So first of all we want to not flip the next bit if the death impulse is zero.
And by the way notice that we have a lot of bits that we're flipping here.
And that's why we made our rep bits a UNT 32.
Remember the original gameplay effect context uses a smaller one, doesn't it?
It uses a UNT eight.
Right.
So we're using something a little bigger so we can accommodate for more bits, 32 to be exact.
So we're going to flip the 14th bit, but only if our death impulse has been set.
So we can say if not death impulse dot is zero.
And this checks to see if it's exactly zero, which it will be if we've never set it because we're initializing
it to the zero vector.
So if that's the case, if it's not zero, we're going to flip the 14th bit by taking rep bits using
a bitwise Or equals one left shift 14.
Now that means that we can check to see if that bit has been flipped down here where we're serializing.
So just after checking the 13th bit we're going to check the 14th.
So we're going to say if rep bits bitwise and parentheses one left shift 14.
So we'll see if that bit has been flipped and if so, we need to serialize the vector.
Now, I didn't want to give this to you as a challenge, because I didn't want you to get confused and
think that because our damage type, the gameplay tag and our hit result, the hit result are structs
that you'd have to do the same thing with our f vector as you did with the other structs.
Namely, use shared pointers and go through all that.
You really don't have to with a vector.
All you need to do is treat a vector like the other smaller data types, and the f vector actually has
the inherent capability of.
Net serializing.
All we do is take the death impulse vector and call net serialize on it, which can take the archive
we can pass in R, it can take the map, we can pass that in, and a boolean we can pass in B out.
Success and death impulse will be serialized this way.
So now you know how to serialize a vector too.
Okay, so now our effect context has the death impulse.
Now we can set that death impulse.
Now the last crucial step that we can't forget is we have to scroll up to where we're calling serialized
bits.
And now we need to serialize another bit.
We have to change this from a 13 to a 14.
Now if we go back to or a projectile.
We need to figure out how we can set that death impulse on the effect context.
Now we can't really do it after applying the damage effect.
We have to do it before.
So even though we made this apply damage effect, return a gameplay context handle.
If we say stored that in a local variable and then set the death impulse on it after, it would be too
late because applying the damage gameplay effect would happen first.
So we need that context to have its death impulse set before applying the effect.
So for that reason, I'd like our damage effect params to carry that death impulse along with it.
Now we know that it carries along its death impulse magnitude, but what really counts is the actual
death impulse itself.
So the effect params could carry the magnitude up to this point, where on sphere overlap can get the
direction of the projectile.
I'll scale it by that magnitude and then set that death impulse in the effect.
Params which apply damage effect could take in and set it on the context.
So we're going to go back to aura ability types up to the damage effect params.
And not only is it going to have a death impulse magnitude, it's also going to have an f vector called
death impulse.
Now it'll be a zero vector by default.
With its own new property.
And we're going to set this in or a projectile before passing in the damage effect params.
So we're going to make a const f vector.
Called death impulse and we can get the direction of the projectile with get actor forward vector,
but we can scale it by the death impulse magnitude that's carried along in damage effect params.
It's damage effect params dot death impulse magnitude.
Once we have that death impulse, we can take damage effect params dot death impulse and we can set
it to death impulse.
So now apply damage effect is going to take in damage effect params.
So we have a death impulse vector on these params that are a damage gameplay ability doesn't fill in
here, because there's really no way to know what that death impulse direction should be right here.
So that'll be something designed to be set later.
So or a projectile will set it here equal to its own actor forward vector scaled by the magnitude.
Now apply damage effect is going to need to set the death impulse on the effect context.
So if we go back to apply damage effect and aura ability system library.
Here's the h file.
Here's the cpp file, and we can go down to apply damage effect.
We see that we are making an effect context handle, but we're not actually doing anything with it except
adding a source object using the avatar actor.
But what we can do now is we can actually go ahead and set the effect contexts death impulse.
Now, I'd like an easy to use setter for it and an easy to use getter for it here on the ability system
library.
Just like our other variables in the effect context, we have getters and setters so that we don't have
to perform this cast to aura effect context elsewhere.
So we're going to create those.
But those also require getters and setters on the effect context struct itself.
So if we go back to our aura ability types and to do that I'm going to have to close a couple tabs.
Here is aura ability types dot h.
We can go ahead and add getters and setters for the death impulse.
And we can do that really quick.
We can make an f vector returning function called get death impulse, which can be const and can return
death impulse.
And we can make a void function void set death impulse, which can take in a const f vector reference
called in impulse, and we can set death impulse equal to an impulse.
So as simple as that.
And then our ability system library can make some ability system library functions.
We'll make one for get death impulse by copying get damage type.
And all we have to do is change its type to F vector.
Change its name to get death impulse.
And give it a definition.
And it can be actually almost identical to get damage type.
So we can paste that with a couple key differences.
If we can't do a successful cast I'm going to return f vector zero vector.
So not just an empty f vector, but a zero vector.
And once we're inside the if statement, I'm going to return or effect context.
Get death impulse.
That's it.
So now we can make the setter function and it's going to be just like set damage type, which I'm noticing
now doesn't have a new function.
We can just give it the same function as set debuff frequency blueprint callable category this category.
And I'm going to copy this function.
And we'll make our set death impulse function.
So it's going to be called set death impulse.
And it'll take the context handle but not a game play tag.
Instead a const f vector reference called in.
We'll call it an impulse.
And with this we can go ahead and generate the definition.
And looking at set damage type we can copy it, we can paste it.
And the difference here is we're just going to take aura effect context and call set death impulse and
pass in an impulse.
Simple.
So now we have these setters and getters right.
Nice and convenient.
And we know that if we scroll all the way down to apply damage effect, that our damage effect params
should have a death impulse that we can use to set the death impulse on our effect context through its
handle, so we can call set death impulse and pass in effect context.
Handle and pass in the death impulse in damage effect, params, damage effect, params dot death impulse
and with that the context handle will be set.
And if we go all the way back to aura projectile, we know that because we're setting the death impulse
here that when we call apply damage effect, the effect params that we're passing in will have that
death impulse, and the ability system library will handle setting it on the effect context.
And then by the time we get to the attribute set, when we know damage is fatal, we can get that.
So the last piece of this puzzle is to go all the way into aura attribute set right here, and handle
incoming damage.
As soon as damage is fatal, we can use that death impulse.
So right here and if be fatal, we're going to have a to do.
Use death impulse and we'll handle that in the next video.
For this video, that's enough, and hopefully we'll make some enemies fly around upon death.
Excellent job, and I'll see you in the next video.