Welcome back.
So we've got some sounds now, and our Goblin spear is just a little bit better.
But I'd like even more effects.
I'd like effects for when the spear impacts with something, but I don't want to just add some kind
of a notify in the montage for the attack because if the spear just misses, I don't want anything there.
But if it does get a hit, I want to see some kind of impact effect and perhaps hear an impact sound.
So what we're going to do is let's see what effects we have.
We'll go into effects combat and blood impact.
Now we have this blood impact.
It's a little bit cartoony, but that fits with the style for the rest of the assets in this project.
But if you're using your own assets, of course you can use really any effect that you want.
But this is a nice flashy blood effect.
And I'd like to play this, but the thing is, different characters might have different impact effects.
You might have some kind of fantasy creature that has blue blood or green blood or something.
And by the way, if you wanted a green blood splatter, you could come into this blood impact.
I would duplicate it first, but then you could go to initialize particle.
And here's the color here used by this effect, you could change it to green if you wanted to like this
and then you'd have a green effect.
I'm going to control Z to undo that.
But just showing you that it's pretty easy.
And because we could do this, I'd like the blood effect to be retrieved from the target that we hit
with our melee ability.
So our melee ability is causing damage.
What it can do at the same time as it causes damage is it can spawn some kind of blood effect.
Now, being a top down game, I'm not too concerned with 100% accuracy location wise.
When we hit something, when we hit something, I'd like to spawn that blood effect just about at the
tip of the spear.
At the tip socket.
So we can get that combat socket location associated with the montage.
We have that in our ability as well.
So since we need to get the blood effect from the target that we're hitting, that would be a good thing
to first of all, add to our base character class and then add a function to retrieve it from our combat
interface.
So we have two things that we're going to want to do here.
So we're going to do that on the C plus plus side.
So I'm going to close the editor.
And from here in Writer, I'm going to go into the character folder, into Aura character base, and
I'm going to add a Niagara system variable that we can set from blueprint for the impact specifically
for blood.
So just at the bottom of our protected section, I'm going to add a new variable.
It's going to be a U.
Niagara system.
Writer is going to ask if I want to forward declare it.
I do.
And this will be.
Blood effect and it's going to be added anywhere and we'll make it blueprint read only so we can access
it from Blueprint as well.
Now I want a function to return this, but I want it on my combat interface so we don't have to cast
two or a character base or one of its child classes.
So we're going to go into interaction combat interface.
And here in the combat interface, we're going to make a Blueprint Native event, and I'd like it to
be Blueprint Callable as well.
So down at the bottom I'm going to make a function that returns a you Niagara system pointer.
I'm going to add the forward declaration up there.
So Ryder just stuck it way up there.
That's fine.
And I can drag this you anim montage way up there as well.
That's fine if that's up there too.
And this will be a pointer and we'll call this function get blood effect.
And as I mentioned, I want it to be a blueprint native event.
So we'll go ahead and copy the U function for this Blueprint Native event.
And we can override the implementation version in or a character base and just return that effect.
So we'll do it Inside of this comment section here, we're going to say virtual you Niagara system pointer,
get blood effect implementation and we'll go ahead and generate the definition and return our blood
effect.
Cool.
Okay.
So now that we have a way to get the blood effect, we're planning on getting that from the victim.
We're hitting an attack montage.
Should have some kind of hit sound as well, some impact sound.
But it's going to depend, I think, on the montage itself, because we might have one attack animation
that swipes with a hand, another attack that swipes with a weapon.
So I think this should be closely linked up with that attack animation.
Now, if we go back to our character base and we search for attack montages, we have the array of tagged
montages.
And if we just go to the declaration or usages, we see that it's in the combat interface, we could
easily associate a sound effect with a given attack montage that we can play or not play, depending
on whether we got a successful hit.
So I'm going to add a U sound base pointer to this and I'm going to call this impact sound and set it
to null by default null pointer.
Give it the same U property as the others in the struct like so.
And now we can set an impact sound per attack.
Okay, so let's go ahead and compile and launch.
All right.
So back in the editor, what I'm going to do is first open up aura character and I'm going to search
for combat.
And here's my blood effect.
I'm going to set that and I'm going to choose blood impact for that.
So now Aura has a blood impact.
Now we can just go into the character folder and BP enemy base and just set this on the base enemy blueprint
as well.
So I'm going to search for blood and set that to blood impact.
And now all enemies will just have that red blood.
But you can override that per enemy if you like.
So now our Aura character has blood.
We can also go into our Goblin Spear blueprint, BP Goblin Spear into its attack montages and notice
that the single array element in attack montages now has an impact sound.
So what would be a good impact sound to play in the event that our Goblin Spear hits something?
Well, let's take a look at content assets.
Sounds and hidden within some of these folders there's a sound I think I'd like to play.
If we go into Enemies Ghoul and Swipe, I think this would be a pretty decent impact for a spear.
So I'm just going to make a sound effect here and I'd like to go to the Sounds folder into the SFX template
multi.
I'm going to copy that into the swipe folder in Ghoul.
So drag over to swipe copy here and open that.
I can go ahead and just rename it right away to SFX, underscore swipe and I can open it up and I'm
going to open the content drawer, click doc and layout and I'm going to go into Enemies Ghoul Swipe
and get these three.
I'm going to select my input array and drag all three in for that and press play.
And there it is.
Now it's a bit loud.
So I'm going to select my volume multiplier and put this way down like 0.1.
That might be a little too low.
So let's go.
0.25.
And I think that sounds pretty good.
And of course, you're going to want to test this.
Ideally, you would test with some studio monitors as you're playtesting the game and make sure everything
is just right.
So I'm going to put this SFX swipe into my Goblin Spear and its attack montages array right here for
the impact sound.
So with SFX Swipe selected and I can set that impact sound.
So now that I know this is set, at least for Goblin Spear, I can go about playing this sound effect
and spawning the blood particles and I'm going to do that in my melee attack ability.
So I'm going to go to content blueprints, ability system, enemy abilities and open gar melee attack
and go all the way to the end here where what we're doing is causing damage.
But we're doing so in this for loop and a for each loop looping over all live players within radius.
Now we're checking to see if it's a friend and if it's not a friend, we're causing damage.
Well, we're also going to do is spawn those blood effects.
Now, remember, we're going to spawn the blood effects at the tip of the spear.
So if this goblin happens to damage to auras or to player controlled characters that happen to be within
the radius of that sphere at the tip of the spear, there's really no point in playing to impact sounds
and spawning two blood particles unless, of course, both characters had different blood particles.
So I guess in the case of blood particles we could spawn two blood particles, but no point in playing
the impact sound more than once at the same time.
That's just not necessary.
So what I'd like to do is if we reach the true case here, I'd like to create a Boolean variable called
hit target.
Or rather than hit Target, I'm going to call it has hit target as hit target sounds like a noun, like
something that you would store, like a reference to a hit target.
But this is a boolean, whether or not we have hit a target and if we've caused damage, we're going
to set has hit target to true.
And by the end of this, before we end our ability at the end of this, for each loop we're going to
check that has hit Target Boolean.
And if we have, then we're going to play the sound once.
So we're going to use has hit target for the condition and we'll play that sound.
But regardless of whether we play the sound or not, we're going to end the ability so both the true
and false will end the ability.
But in the true case here, we're going to play one sound and that's going to be the sound associated
with our tagged montage.
Now notice we have an impact sound.
We're going to drag that down and create a reroute node and we're going to reroute it all the way over
here.
So another reroute node and then we're going to play this sound.
So what we're going to do is play sound at location.
And what is the location?
It's going to be the combat socket location that we got here.
So we'll hook that in.
Just tidying this up a bit.
And this will be for the true case.
So the true case, we play the sound, but we also end the ability right after.
Okay.
And then, of course, we can spawn the impact particles.
We could do that right here when we cause damage.
So we're going to use the blueprint callable function, get blood particles or get blood effect, we
called it.
And this will be on the target, which is the array element here in the for loop.
So we're going to get this node here, add a reroute or reroute it over here.
And we're going to get that blood effect and we're going to spawn system at location.
Like so.
And the system will be the blood effect and the location is going to be this combat socket location,
which I'm now starting to think that I should store in a variable so we can keep this a little bit neater.
So I'm going to just highlight from this point backward and bring things back a bit.
And I'm going to promote this to a variable and call this combat socket location and we're going to
set that as soon as we've gotten it.
And use it here.
And then we can just use a getter for it.
That's what I prefer to keep these nodes under control.
We'll just use a getter for that combat socket location.
And we don't need to drag too many wires all over the place.
And we're going to use that combat socket location here.
We can leave the rotation at zero and the scale at one.
All the rest of these settings can be at their defaults.
That looks good.
Now, we did store our tagged montage in a variable as well, so we really don't have to run this big
root node over here if we don't want to.
We could just get that tagged montage out and break it and we can get that impact sound and hook it
in directly here.
So just minimizing the number of nodes that we need reroutes for and that looks better.
We can do the same thing right here if we wanted to as well.
For now, I think it's okay.
Okay.
Now the thing is, we're setting these each time we activate the ability.
But if we go to class defaults and scroll down, we see that this is instance per actor.
So that's okay that we have these member variables, but just realize that they keep their values each
time we activate the ability.
This ability has been instance and it sticks around.
So in the case of combat socket location, for example, that's fine.
We're setting it before we use it.
But something like has hit target.
This boolean should be set to false at the very beginning when we activate the ability because if we
ever set it to true, it'll still be true next time we activate it.
So we're going to set it to false at the very beginning of the ability and this on end ability is getting
in my way, so I'm going to delete it.
Okay, so now we should see and hear some additional effects.
Let's save all and go ahead and let our spear enemy attack us.
I'm going to go ahead and just remove the other enemies from the world so we can test just the spear
enemy.
And there we go.
All right.
It looks and sounds great.
Much better, right?
Excellent.
And of course, we can increase the number of players to two.
Now let's take a look on the client.
And notice that we don't get our impact effects.
We don't get the sound and we don't get that blood either.
So why is that?
What's going on here?
Well, we're playing the sound and spawning those particles from a melee attack.
Now, this is something that we execute on the server.
We're executing it from a behavior tree task.
And this is for a or enemy or a enemies are not controlled by a player.
They're controlled by AI.
Now we know that gameplay abilities are automatically replicated, right?
Well, they're actually replicated to the owning client only.
And no real players own this enemy, AI controlled character.
So if we're spawning a system here in the gameplay ability and we're playing a sound, this is only
going to happen on the server.
It's not going to replicate to anyone because as no one owns this.
So for that reason, if we want some cosmetic effects, we need a way to replicate those.
And gas has a built in way to replicate those types of effects and that way is via the use of gameplay
queues.
So we're going to finally learn a little bit about gameplay queues so that we can get these types of
effects working in our game and we'll handle that next.