Welcome back.
Now our beam looks great, but we want it to sound great too.
So we're going to add sound in this video.
But before we do that I'm going to show you one side effect of multiplayer.
Let's go to the number of players and set it to two and press play.
I'm going to put.
The screens on both sides.
Right here I have the server and on the right is the client.
Now on the client notice things are working just fine.
And we see this both on client and server.
But on the server if I right click and hold well notice the server owned character on the client here
does not stay in that shock loop.
It just goes back.
Well that's because that shock loop variable is not replicated and it's used in the animation blueprint.
So if we go to a character and we select in shock loop and we come over to the details panel and under
replication we select replicated.
Now it gets those two white balls there.
It's now a replicated variable.
And now we should be able to see it.
Let's test that.
So on the server I'm going to electrocute and notice on the client we're in the shock loop.
It looks great.
So that's going to take care of that problem.
But it's still silent.
And we want sound, right?
So let's go to our gameplay cue shock loop, go to while active and let's spawn a sound as well.
So I'm going to right click in here.
And I'm going to use spawn sound attached.
Now if we use spawn sound attached, it returns the audio component.
We can hold on to that until we need to remove it.
So I'm going to take its return value and promote it to a variable called shock loop sound.
Now spawn sound attached needs a sound.
We can go into assets, sounds, abilities, shock and use shock loop.
Here's what it sounds like.
I'd like to use that here.
So I'm going to set that.
Now the attach to component.
It doesn't matter what we attach it to.
But just because we can we can attach it to the target attach component which we know is the weapon.
So I'm going to promote that to a variable as well.
And this will be simply target attached component.
And we'll use that for the attach to component.
In fact, we could specifically attach it to the tip socket if we wanted to.
Okay, now I'm going to check stop when attached to destroyed and make sure auto destroy is checked.
And with that, we're spawning the sound and we just need to remove it.
And on remove.
So here in on remove, what I'm going to do is after we've destroyed the Niagara system component,
I'm then going to get my shock loop sound.
I'm going to convert it to a validated get.
And after destroying the component we're going to get it.
But if our beam system is not valid I'm still going to check the shock loop.
So I'm going to reroute the not valid node.
Around my destroy component.
Node and hook that in here too.
Now if we just destroy the sound component, it's going to sound pretty abrupt.
In fact, let's just see what happens if we do that.
I'm going to take it.
And we can call destroy component.
Let's see how this sounds.
So it's kind of abrupt.
I'm going to set the number of players down to one.
Try it on the server.
So notice that the sound is abrupt and I don't like that super abrupt change.
So instead of just destroying the component, I'm going to call a function.
Called Fade Out.
And fade out has a fade out duration and even a fade curve.
Now, if I choose a fade out duration of 0.3, we can see how that sounds.
So it's not so abrupt.
I like that, and if you like, you can choose a different kind of curve for it to fade out like a sign
or an S curve.
I kind of like how that sounds.
So I'm going to leave that at sine curve.
And regardless of whether the shock loop sound is valid or not, we're also going to hit that return
node.
No matter what.
So I'm going to reroute this around and stick it to the return node.
And that's what on remove looks like.
Okay, so now Shock Loop has sound and it sounds pretty awesome.
Awesome.
All right, so things are looking good.
It's not really functional.
We're not causing damage or anything.
So there's still some work to do, but we're making progress and we'll continue to do so in the next
video.
I'll see you soon.