‫Hello.
‫Welcome.
‫In this lecture, we are going to be making sounds.
‫So we'll have a muzzle sound and we'll have an impact sound.
‫Let's dive in and see how we're going to do that in the process.
‫We're going to learn how we can attach sounds to other components so they move with them, such as the
‫muzzle.
‫So now that we've got a nice and tidy pull trigger function, it's quite clear where we want to be making
‫sound effects.
‫Now in my game, the only real sound effects I want are on the muzzle flash and on basically the impact.
‫So the places where we're already spawning emitters, I just want to add sound to that.
‫Now that's relatively straightforward.
‫We've done similar things in the past with the gameplay static, so you can do a play sound at location,
‫which is going to play that sound unattached to any object.
‫So it won't be moving around.
‫It will just stay fixed in that location until it's finished.
‫However, we also want to be able to play and attach sound in the same way as we're playing an attached
‫emitter up at the top.
‫And for that, that's fairly straightforward.
‫What we're going to look for, though, is, first of all, we're passing in this type and let's try
‫and understand that a little bit better.
‫So we've got the play sound at location, which takes in the world context, but it also takes in this
‫you sound base.
‫Now why is it a sound base and not just a sound wave?
‫Because if we go over into unreal, go into our asset packs, shoot a game, sound's weapon, assault
‫rifle and mono, you're going to see that if we hover over any of these clips, then the type here is
‫sound wave.
‫And that actually corresponds to a type and unreal called you sound wave.
‫And if we go and have a look at that sound wave class, you can see that it inherits from you sound
‫base.
‫So what is sound base?
‫What else inherits from it?
‫Well, something called an audio cue or sound cue, which we're going to be using in the next lecture,
‫which allows us to do more complicated things with sound waves, such as randomize them and modulate
‫their pitch.
‫So we're not interested in those just yet, but just know that these functions will work just as well.
‫Whether we're passing in a single sound wave or a collection of sound waves gathered together in a sound
‫cue.
‫And that's by virtue of the fact that they take in a sound base which encompasses both of those types.
‫So what's useful is if we go and look through our gameplay statics for the use of sound base, what
‫else can we play a sound with?
‫Well, here there's a spawn sound at location, a slightly different variation on the previous function.
‫You can see here it returns the audio component that it's spawned.
‫We're not interested in that one though.
‫What we are interested in is our spawn sound attached.
‫Now this takes in our sound and then it also takes in a component that we want to attach it to as well
‫as an optional attach point if we're dealing with a skeletal mesh.
‫So that's the one we're going to want to use.
‫So I'm going to go over into our gun.
‫CP And in order to call it, we're going to need a sound to call it with.
‫So we're going to add that to our configuration in the header file where I'm going to add ourselves
‫a new UE property and I'm going to add it just under our muzzle flash called You Sound Base is going
‫to be the type star and it's going to be the muzzle sound like.
‫So now that we can then configure in the editor and I'm going to go over to the gun CP and we're going
‫to spawn.
‫So it's new gameplay statics again and we're going to call Spawn sound attached and we're going to pass
‫in this time instead of the muzzle flash, the muzzle sound, then we've got to attach it to a mesh
‫and to a socket.
‫And actually for that I'm just going to copy both the mesh and the socket from above because we want
‫to be doing it to exactly the same location, essentially having the sound come out of the end of the
‫barrel of our gun.
‫And if go ahead and compile, we should be able to go over to our rifle, BP, and find a new property.
‫Sure enough, when the compile finished, the muzzle sound property popped up here and we can select
‫from the dropdown one of the sound wave files.
‫We don't currently have any sound cues or we do.
‫They come from the engine, but we don't want any of those.
‫We're just going to go with the assault rifle shot and if we go and play, you can see that we are getting
‫the correct sound effect when firing the rifle.
‫It's now time for your challenge to play the sound at location.
‫That is the function you've probably used before to play an impact sound of which we have a few in here.
‫When I did my dropdown, you could see there was the assault rifle shots.
‫But if we also look for assault rifle, we can see that there are these impact concrete sounds as well.
‫So you might want to choose one of those.
‫So you're going to play an impact sound.
‫You're going to use the Le Sound at location from gameplay statics, hook it up and test it out to see
‫that you're getting both of those sounds in your world.
‫Pause the video and have a go.
‫Okay.
‫Welcome back.
‫So let's give this a shot.
‫First things first, let's set up the configuration.
‫So I'm going to mostly copy the configuration from the muzzle sound, put it underneath the impact effect,
‫and I'm going to call it the impact sound.
‫Then what we're going to do is just set it off compiling because we made a change to our head of file
‫and I want it to be quick.
‫Then we're going to go down to where we're spawning our emitter at a location.
‫We're going to do a new new gameplay statics colon, colon.
‫And we're going to be doing a instead of spawn sound attached.
‫It's going to be a play sound at location.
‫We're going to have to give it a world context.
‫I'm going to do a get world.
‫Then we're going to give it the sound that we want it to play, which is going to be the impact sound.
‫And then we need to give it a location to play the sound out, which is going to be the same as the
‫location for doing our particle effect and direction.
‫Doesn't matter in this case because our sound is going to be the same in all directions.
‫Put a semicolon on the end of that line and go and compile it and head over to the beep rifle where
‫we now have the new configuration variable for the impact sound.
‫As I said, there's going to be something with impact concrete in it.
‫So I'm going to go and select number one from that, go ahead and play and try this out.
‫And as you just heard there, we were getting an impact sound when we were hitting something.
‫And if we weren't hitting anything but just shooting, all you were hearing was the rifle muzzle sound.
‫So that's it for this lecture.
‫We've seen how we can spawn a sound attached to an object.
‫The next lecture, we're going to be looking at how we can randomize those sounds so they aren't always
‫exactly the same every time they're played.
‫See, they're.