‫Welcome back.
‫In this video, we're concerned with playing sounds.
‫We'd like to play some sounds when we fire the projectile.
‫When the projectile hits something and when one of our pawns dies.
‫So let's jump right in.
‫Now I'm here in the ED, and if I go into the assets folder, we have this audio folder and we have
‫two different sounds and these will be good for when our projectile hits something.
‫We'll use the thud and when one of our pawns dies will use the explode audio.
‫And we can also reuse the thud audio when we're launching a projectile.
‫Now we'd like our projectile to have two variables representing those sound assets.
‫Now, down here in the private section, I'm going to add a couple of variables and I'm going to forward
‫declare this class.
‫Now, the class I'm going to use is you sound base and that's going to be a pointer.
‫Now I'm going to call this launch sound.
‫This is going to represent the sound that we play when we launch a projectile.
‫Now, you sound base is a class we can use for sounds.
‫Now if we expose this to blueprints, we can set this using our sound assets that we have in our sounds
‫folder.
‫So I'm going to go ahead and give this a U property so we can expose it.
‫And I'm going to make it edit anywhere and place it in the category of combat.
‫So it's in there with our other combat variables.
‫Now I'd like another use sound based variable for when the projectile hits something.
‫So this will be another U sound based pointer.
‫And I'm going to call this hit sound and I'm going to give this the same you property as launch sound.
‫Now notice I'm not forward declaring you sound base for hit sound that's because I've already forward
‫declared you sound base up here.
‫So once you've forward declared a type on a line, that type can be used after it in the file.
‫Now for this reason, some people put their forward declarations all the way up here at the top.
‫That's another way to do it.
‫So if I said class, you sound base up here, then this takes care of forward declaration and I can
‫use the use sound base type anywhere in this file after the forward declaration.
‫So that's another way to do it.
‫So just to show you both ways, I'm going to forward declare you sound base up here at the top rather
‫than forward declaring it down here.
‫So we now have to use sound base variables on projectile h.
‫I'd like to add a sound base to the base pawn class and this will be for when the base pawn is destroyed.
‫So this will be in the private section and I'm going to forward declare it here and it's going to be
‫a you sound base pointer and I'm going to call this death sound and this is going to get a you property.
‫I'm going to scroll down so you can see it better you property.
‫It's going to be added anywhere.
‫And I'll place this in the category.
‫Combat.
‫So now that our base -- and our projectile have used sound base variables, let's go ahead and compile
‫these and take a look at these variables in Blueprint.
‫And of course, I get a compilation error because I typed you property a bit too hastily.
‫That lowercase y should be an uppercase y.
‫These things are case sensitive, so correcting that typo and compiling again, I now have a successful
‫compile.
‫So let's hop back into the editor now here the editor, I'm going to go ahead and open up the actors
‫folder and BP projectile and I'm going to open full blueprint editor I just prefer to do that.
‫It makes it easier for me to see where everything is now.
‫I have the launch sound and the hit sound here and because these are edit anywhere we can select sound
‫assets from the dropdown and it just shows me the valid options I have.
‫Now what I'm looking at here is launch sound and I'm going to use the thud audio for this.
‫Now I'm going to use Thud audio for the hit sound as well.
‫But I made two variables.
‫So if you get your hands on more sound effects, you can use a different sound for the launch versus
‫the hit sound.
‫So this is set up for you in case you like to do that.
‫Now that takes care of launch sound and hit sound on the projectile.
‫So I'm going to compile and save and close out of this.
‫Next, I'm going to open ponds and open BP pond tank.
‫And here's my death sound in the combat section.
‫I'm going to click the dropdown and use explode audio and set death sound to the explode audio sound
‫asset.
‫I'm going to compile and save that and close out of BP pond tank and open BP pond turret because we
‫put this variable on the base pond class which the turret also inherits from.
‫So I'm going to set death sound to explode audio here as well.
‫So now we have sound assets and they're stored in variables both in our ponds and on the projectile.
‫The only thing that's left is to actually play these sounds.
‫Now you game play statics has another useful function.
‫It's called play sound at location.
‫Now we can scroll down and see that it takes quite a number of input parameters, but like most of these
‫functions there are a number of optional parameters that have default values.
‫So we can dig into the code to see this.
‫So I'm going to hop into projectile CP and here and begin play.
‫I'm going to type you gameplay statics, play sound at location and hit that opening parentheses there
‫and I'll see that it says one of two.
‫Now this first version it's showing me takes a world context object.
‫We know we can pass this in for that.
‫And next it takes a use sound base.
‫So we have sound base variables and next it takes an F vector for the location.
‫Now, if we want to play the sound at the location of the projectile, we can just use get actor location
‫and the rest of these inputs are optional.
‫So if you'd like to look into those, take another look at the documentation page for this function
‫and do some more research.
‫But we are only concerned with the first three inputs so we know how to play sounds at locations we
‫can use you.
‫Gameplay statics play sound at location, which takes a world context object, a sound which we can
‫use our use sound base for and a location which we can use get actor location for.
‫So your challenge will be to call play sound at location and play sounds for the various aspects of
‫our gameplay that needs sounds.
‫So call you gameplay statics play sound at location in the projectile class first in the on hit function
‫and use our hit sound variable.
‫Do this in the if check when we check to see if other actor is valid as well as make sure the other
‫actor is not this or the owner.
‫But call it before we destroy the projectile and call play sound at location and begin play for the
‫projectile and use the launch sound.
‫That way we'll get the sound played when the projectile gets spawned as well as when the projectile
‫hits something next.
‫Go into the base pong class and call play sound at location and handle destruction.
‫And you're going to use the death sound.
‫That's the explosion.
‫So pause the video and add these calls to play sound at location now.
‫Okay.
‫So first we're here in Projectile CP and I'm going to go in order of the challenge.
‫So first I'm going to go down to on hit and play the sound down here.
‫Now you probably checked to see if the sound was null and if you did, I give you kudos because you're
‫already getting those good programming habits.
‫Now, if you didn't, that's okay.
‫Go ahead and do it.
‫Now.
‫We're going to check to see if hit sound is valid before we call the new gameplay statics function.
‫So it's going to be you.
‫Gameplay statics play sound at location and we first need a world context object that's going to be
‫this.
‫Next we need the hit sound itself and we're going to play this at the actor location.
‫So get actor location will satisfy that third parameter.
‫Okay, perfect.
‫Next, we need to play a sound and begin play.
‫So let's go back up to begin play.
‫And for this one, we're going to check to see if the launch sound is valid.
‫So we're going to say if launch sound you game play statics play sound at location and of course we
‫need the world context object.
‫That's this the use sound base is going to be launch sound and we're going to play this at the actor
‫location.
‫So get actor location and that takes care of playing the sound and begin play.
‫So the last thing to do is to play the sound on the base -- class and handle destruction.
‫And now that we're handling visual and sound effects, we don't need to say to do here because we have
‫done this.
‫So first, we're going to check to see if death sound is valid.
‫If it is, then we can call you gameplay statics play sound at location with the world context object.
‫That's going to be this the sound base that's going to be death sound and get actor location will satisfy
‫the location for this death sound.
‫Ock Awesome.
‫Let's go ahead and compile our code with a successful compile.
‫We'll hop back here into the editor and let's play test this.
‫So I'm going to hit play and wait for the timer.
‫So in summary, we now have sound.
‫We're playing a sound for the projectile on hit and on launch, and we're playing a sound for the pawn
‫on death.
‫So looking back at our section plan, we see that we've checked off just about every single item here.
‫We're still on the special effects we got the smoke, the explosions and the sounds.
‫There's just a few things to do to polish up this game and make sure it's looking and feeling right
‫before we go ahead and wrap up this section.
‫So I'll see you in the next video.