Welcome back.
So here's what our gameplay ability for hit React looks like.
We apply a gameplay effect.
We store the handle for that effect.
We get the avatar actor from actor info.
Cast it to the combat interface and use get hit react montage The blueprint native event that returns
that montage and we play montage and wait.
Now we have set that variable for our goblin spear and goblin slingshot, but we're never actually activating
this ability.
So we want to do that when our enemies get damaged but are not dead.
So let's go into our attributes set.
And the reason is because here in aura attribute set, we know when the affected attribute is the incoming
damage attribute.
In fact, we know if the damage was fatal because we know that new health will now be equal to zero.
If that's the case Now, if the damage was not fatal, then we should tell the enemy to activate its
hit React ability.
That means our enemy should have that ability.
So we need to handle a few things here.
We need to make sure that the enemy has the hit react ability and then we can try to activate that ability
from here in the attribute set.
So how do we make sure the enemy gets that ability?
Well, we do have a data asset for things that all enemies should share.
We know that that's an ability system data and it's called character class info.
Now all enemies may want to share gameplay abilities so we can have a array of gameplay ability classes
that we'd like to apply.
So in this video we're going to add that to the character class info so that we can add that gameplay
ability and then all enemies can have that gameplay ability.
In fact, they can have all of the abilities in the array that we create here.
So let's do this.
So we'll make a T array.
And the type for the array is going to be a subclass of and the type for the subclass of will be you
Game playability.
We can call this abilities and this will be a edit defaults only property and we can put this in common
class defaults as this will be common to all classes so we can really just call this common abilities,
but it doesn't really matter.
We have an abilities array and we're going to want to set that.
Now, once we've set that in the data asset, then we can make sure that all enemies have these abilities
given to them.
Now, how are we giving our abilities to Aura?
Well, we can remind ourselves by going to character and or a character base.
And we have an Add character abilities function here.
We can check out its implementation on Aura character base.
We see that we're getting our aura ability system component and calling add character abilities here
and the aura ability system component is just taking in a array of start up abilities.
We can check out that definition and we see that it just loops through the array.
It creates an ability spec makes that ability have level one to start and it checks that abilities,
start up input tag and adds that to the abilities dynamic ability tags before calling give ability.
Now this is all very much specific to the player controlled character.
Enemies don't need to care about their input tag.
This is only for player controlled characters that are applying input.
All we really care about is the ability system component calling, give ability, but the abilities
are going to be on that data asset which exists on the game mode.
And remember, we're giving our start up attribute effects using our Ability system Blueprint library,
which we called or ability system library.
We have the static function initialized default attributes.
Well, we could do this for our default gameplay abilities as well.
And this can be pretty simple.
It doesn't even need to know the level or the character class.
It'll just need a world context object and the ability system component and it can get that character
class info from the game mode.
So we'll just make a static function to initialize enemy gameplay abilities.
It'll be static void and we'll call this give startup abilities and this will take a const object called
world context object and it'll take a you ability system component called ASC and this can be blueprint
callable and we'll put it in the same category character class defaults as our initialized default attributes
and we'll go ahead and generate the function definition for this.
And this will be pretty simple.
We're going to get the aura game mode like we're doing initialize default attributes passing in that
world context object and we'll return if that game mode is null.
And once we have that, we can get that character class info from it and from the character class info,
we can get the array of abilities, we can loop through it and have our ability system component, give
the abilities with give ability.
So let's take the first two lines from the function above and paste them here.
So we're getting our aura game mode.
After that, let's get the character class info, that data asset.
We'll get that here.
After we have that character class info, we can get that array of abilities from character class info
so we can say character class info and we can get common abilities.
We can loop through these common abilities with a for loop.
We can say for auto ability, class in character, class info, common abilities.
And we see that this is a subclass of gameplay ability.
I can go ahead and change that to subclass of you gameplay ability if I like.
And we can take the ability system component and call give ability and this requires an ability spec
so we can create one of those.
In fact we can just cheat and go back to aura ability system component and see what we did here.
We took the ability class, we created a gameplay ability spec and made it like this.
We can just copy that line and back here in our Ability system blueprint library, we can paste it here.
We have an ability spec that we can pass in to give ability.
So we now have this nice function give startup abilities that we can call to give abilities to our enemy
and we can do that right here in enemy CP.
We can do it in begin play as soon as we know that our ability system component is initialized, we
can give those abilities and we do that with you.
Aura, ability, system, library, give startup abilities.
It needs a world context object.
We'll pass in this and it needs the ability system component.
We'll pass in ability system component.
And now we should get those abilities provided that those abilities are in the data asset.
Okay.
So we'll have to remember to add our hit React ability to the common abilities array in the data asset.
Once that's done, this function should give those abilities.
Now for actually activating that ability, we can go back to our attribute set.
So I'm going to close out of a couple of these classes until I see aura attribute set here and right
here.
As soon as we know that the damage was not fatal, we can activate the ability.
We can say, if not be fatal.
We can activate the ability.
Now, how are we going to activate the ability?
Especially because I'd like this aura attribute set to not depend on the enemy class.
I don't want it to care what the owner of this is.
We just want to activate an ability.
Well, here's how we can do it in a nice generic way.
We can activate abilities by ability tag.
That's right.
We can specify a tag or a set of tags and say, hey, activate an ability if you have an ability with
a specific tag.
We do that with the ability system component.
So we know that we have this props data structure that has ability system components.
We know that target ask is the owner of this attribute set right, not source but target the thing being
affected and this ability system component can be used to activate abilities by tag using the function.
Try activate abilities by tag.
Now this takes a gameplay tag container and it has an optional bool Allow remote activation set to true
by default, which basically means that we can call this function from a client and activate it predictively.
Well, we're doing this on the server so that doesn't really matter.
But we need a gameplay tag container to pass in.
So let's make one for gameplay tag container.
We'll call this tag container and we need to add a tag to it.
So we'll say tag container dot add tag.
What are we going to add?
Well, we need to get aura gameplay tags using the get function and from that we need to get our effects
dot hit react tag and we're going to pass that in and then we can call try activate abilities by tag
passing in the tag container.
So this is a nice generic way to say, hey, activate an ability if you have one that has this tag.
Pretty nice, right?
And we know that our enemy is going to have an ability with this tag.
So why don't we go ahead and compile and launch the editor at this point?
Okay.
So attempting to compile.
Looks like I'm getting a couple of errors, so let's address them.
First.
Character class info dot h u gameplay ability undeclared identifier.
So I went ahead and just recklessly made a t array using a type that I didn't forward declare.
Let's go ahead and forward declare that I'm used to right or doing this automatically, but sometimes
it doesn't.
So we'll stick that in there and let's try to compile again.
And there we go.
We have a successful build.
So I'm going to go ahead and launch at this point.
Now, there are a couple things to remember, right?
The data asset needs that hit React ability added to it.
So we can't forget that.
So I'm going to go ahead and click open, but I do want to close some of these, such as the blueprints
for our goblin.
I'm going to close the hit React Slingshot, and I'm not using Firebolt anymore.
I'm not using damage at the moment.
Okay.
Now I need that data asset, so I'm going to go to blueprints, ability system data and open character
class info.
And we know that our common abilities needs to have an element added to it and we need to choose gar
hit react so that our enemies can have that ability granted to them.
Once that's the case, then we can cause damage and our attribute set, if that damage is not fatal,
is going to call.
Try activate abilities by tag using a tag container that contains the hit React tag.
Once that happens, it should activate its gar hit react ability provided that this ability has that
tag now, does it?
Well, no it doesn't.
We have to make sure that this ability has that tag.
Let's go to class defaults here and gar hit react now how do we make sure that this ability has that
tag we add it to the ability tags tag container so we can add effects.
Hit React.
Now effects.
Hit react may not be the most appropriate.
We may want an ability.
Hit react tag.
But that's okay.
We can reuse this tag as long as the enemy has the ability with this effects.
Hit react tag.
It'll activate this ability as soon as try activate abilities by tag is called.
Once that happens, our ability will activate.
We'll apply the gameplay effect to owner.
We'll get the hit React montage or play montage in wait and we should see that montage played.
Let's give that all a try.
Kind of a lot of moving parts here, so let's see if we can at least see that hit React montage played.
And we did little hard to see with the explosion, but it's definitely happening.
Now it's blending in.
So couple of things to tweak a little bit.
We can go into assets, enemies, Goblin and animations slingshot, and we can open that, hit, react
and adjust the blend time.
I really don't want that fast of a blend time, if any.
Perhaps a .05 will do for blend in and blend out.
And same goes for my other enemy, Goblin Spear.
We'll lower that, blend in and blend out time just so we can see the majority of the animation.
And yes, we are definitely getting a hit react, which means our GA hit React is activating.
We're never actually ending the ability and that means different things depending on the class defaults.
If we look at instancing policy, instance per execution means that each time this is activated, a
new instance is created.
But we don't need that.
We can have an instance per actor and that way this will only be instanced once when we first activate
it and each subsequent activation will use the same instance.
Now, that's going to mean that we should make sure to end the ability and in fact, we want to still
remove this gameplay effect.
So let's handle those things.
And I think I'd like to remove the gameplay effect and end the ability when the montage is completed.
I don't want to use on blend out because that happens slightly before the montage is completed, but
if the montage gets interrupted, we should also handle that situation.
Same for cancelled.
So what I'm going to do is remove the gameplay effect and end the ability in these cases on completed,
on interrupted and on canceled.
Now to remove a gameplay effect, that's pretty easy.
We can right click and type remove gameplay effect from owner with handle.
Notice that there are other options with asset tags and with granted tags we're going to remove by handle
and we can easily do that because we've cached our gameplay effect handle called active hit React.
So we're going to bring that in as the handle for stacks to remove.
We can just use negative one and we can do this on completed.
We can do it on interrupted and on canceled.
And as soon as we do that we'll end the ability.
Like so.
So now we can press play.
We can.
Do some damage, we get the hit react and it happens multiple times only, though, if it's not already
active.
So we can see that we get a little bit of a delay there.
And if we'd like this to happen a little sooner, we could in fact do this on blend out.
If we wanted to do that.
But we're not going to get it multiple times as hit react is not ended until the montage is finished.
I'm going to remove this from on blend out.
Okay, so now that we've got this working, we've got a pretty nice hit React ability and we also have
the opportunity to respond to when we begin and end our hit React as we're responding to gameplay tags.
So we can always do things in response to receiving that hit react tag.
So this is looking great.
And now that we have hit reacting, then it looks a little bit more interesting when we actually cause
damage.
Pretty cool.
It's a great job.
And I'll see you in the next video.