﻿1
00:00:10,570 --> 00:00:11,650
‫Welcome back.

2
00:00:11,680 --> 00:00:14,650
‫In this video, we're concerned with playing sounds.

3
00:00:14,890 --> 00:00:18,430
‫We'd like to play some sounds when we fire the projectile.

4
00:00:18,580 --> 00:00:23,380
‫When the projectile hits something and when one of our pawns dies.

5
00:00:23,590 --> 00:00:25,060
‫So let's jump right in.

6
00:00:25,540 --> 00:00:32,770
‫Now I'm here in the ED, and if I go into the assets folder, we have this audio folder and we have

7
00:00:32,770 --> 00:00:38,350
‫two different sounds and these will be good for when our projectile hits something.

8
00:00:38,350 --> 00:00:44,170
‫We'll use the thud and when one of our pawns dies will use the explode audio.

9
00:00:44,170 --> 00:00:48,520
‫And we can also reuse the thud audio when we're launching a projectile.

10
00:00:48,550 --> 00:00:54,590
‫Now we'd like our projectile to have two variables representing those sound assets.

11
00:00:54,610 --> 00:00:59,980
‫Now, down here in the private section, I'm going to add a couple of variables and I'm going to forward

12
00:00:59,980 --> 00:01:01,210
‫declare this class.

13
00:01:01,210 --> 00:01:06,820
‫Now, the class I'm going to use is you sound base and that's going to be a pointer.

14
00:01:06,820 --> 00:01:09,580
‫Now I'm going to call this launch sound.

15
00:01:09,760 --> 00:01:15,250
‫This is going to represent the sound that we play when we launch a projectile.

16
00:01:15,280 --> 00:01:19,570
‫Now, you sound base is a class we can use for sounds.

17
00:01:19,570 --> 00:01:26,050
‫Now if we expose this to blueprints, we can set this using our sound assets that we have in our sounds

18
00:01:26,050 --> 00:01:26,650
‫folder.

19
00:01:26,650 --> 00:01:30,910
‫So I'm going to go ahead and give this a U property so we can expose it.

20
00:01:30,910 --> 00:01:36,100
‫And I'm going to make it edit anywhere and place it in the category of combat.

21
00:01:36,100 --> 00:01:39,550
‫So it's in there with our other combat variables.

22
00:01:39,850 --> 00:01:45,460
‫Now I'd like another use sound based variable for when the projectile hits something.

23
00:01:45,460 --> 00:01:49,090
‫So this will be another U sound based pointer.

24
00:01:49,090 --> 00:01:55,300
‫And I'm going to call this hit sound and I'm going to give this the same you property as launch sound.

25
00:01:55,300 --> 00:02:01,660
‫Now notice I'm not forward declaring you sound base for hit sound that's because I've already forward

26
00:02:01,660 --> 00:02:03,760
‫declared you sound base up here.

27
00:02:03,760 --> 00:02:10,720
‫So once you've forward declared a type on a line, that type can be used after it in the file.

28
00:02:10,720 --> 00:02:16,420
‫Now for this reason, some people put their forward declarations all the way up here at the top.

29
00:02:16,420 --> 00:02:17,950
‫That's another way to do it.

30
00:02:17,950 --> 00:02:26,350
‫So if I said class, you sound base up here, then this takes care of forward declaration and I can

31
00:02:26,350 --> 00:02:32,710
‫use the use sound base type anywhere in this file after the forward declaration.

32
00:02:32,710 --> 00:02:34,420
‫So that's another way to do it.

33
00:02:34,420 --> 00:02:40,870
‫So just to show you both ways, I'm going to forward declare you sound base up here at the top rather

34
00:02:40,870 --> 00:02:43,180
‫than forward declaring it down here.

35
00:02:43,330 --> 00:02:48,830
‫So we now have to use sound base variables on projectile h.

36
00:02:48,970 --> 00:02:55,210
‫I'd like to add a sound base to the base pawn class and this will be for when the base pawn is destroyed.

37
00:02:55,210 --> 00:02:59,920
‫So this will be in the private section and I'm going to forward declare it here and it's going to be

38
00:02:59,920 --> 00:03:07,210
‫a you sound base pointer and I'm going to call this death sound and this is going to get a you property.

39
00:03:07,240 --> 00:03:10,780
‫I'm going to scroll down so you can see it better you property.

40
00:03:10,810 --> 00:03:12,490
‫It's going to be added anywhere.

41
00:03:14,240 --> 00:03:16,760
‫And I'll place this in the category.

42
00:03:18,350 --> 00:03:19,220
‫Combat.

43
00:03:19,700 --> 00:03:26,420
‫So now that our base -- and our projectile have used sound base variables, let's go ahead and compile

44
00:03:26,420 --> 00:03:29,930
‫these and take a look at these variables in Blueprint.

45
00:03:29,930 --> 00:03:35,690
‫And of course, I get a compilation error because I typed you property a bit too hastily.

46
00:03:35,690 --> 00:03:38,420
‫That lowercase y should be an uppercase y.

47
00:03:38,420 --> 00:03:45,530
‫These things are case sensitive, so correcting that typo and compiling again, I now have a successful

48
00:03:45,530 --> 00:03:46,160
‫compile.

49
00:03:46,160 --> 00:03:52,820
‫So let's hop back into the editor now here the editor, I'm going to go ahead and open up the actors

50
00:03:52,820 --> 00:03:59,420
‫folder and BP projectile and I'm going to open full blueprint editor I just prefer to do that.

51
00:03:59,420 --> 00:04:02,540
‫It makes it easier for me to see where everything is now.

52
00:04:02,540 --> 00:04:09,050
‫I have the launch sound and the hit sound here and because these are edit anywhere we can select sound

53
00:04:09,050 --> 00:04:14,390
‫assets from the dropdown and it just shows me the valid options I have.

54
00:04:14,390 --> 00:04:19,400
‫Now what I'm looking at here is launch sound and I'm going to use the thud audio for this.

55
00:04:19,700 --> 00:04:23,000
‫Now I'm going to use Thud audio for the hit sound as well.

56
00:04:23,000 --> 00:04:24,560
‫But I made two variables.

57
00:04:24,560 --> 00:04:30,230
‫So if you get your hands on more sound effects, you can use a different sound for the launch versus

58
00:04:30,230 --> 00:04:31,010
‫the hit sound.

59
00:04:31,010 --> 00:04:33,740
‫So this is set up for you in case you like to do that.

60
00:04:33,740 --> 00:04:38,480
‫Now that takes care of launch sound and hit sound on the projectile.

61
00:04:38,480 --> 00:04:41,810
‫So I'm going to compile and save and close out of this.

62
00:04:42,080 --> 00:04:46,280
‫Next, I'm going to open ponds and open BP pond tank.

63
00:04:46,280 --> 00:04:49,250
‫And here's my death sound in the combat section.

64
00:04:49,490 --> 00:04:56,480
‫I'm going to click the dropdown and use explode audio and set death sound to the explode audio sound

65
00:04:56,480 --> 00:04:57,230
‫asset.

66
00:04:57,260 --> 00:05:04,370
‫I'm going to compile and save that and close out of BP pond tank and open BP pond turret because we

67
00:05:04,370 --> 00:05:09,320
‫put this variable on the base pond class which the turret also inherits from.

68
00:05:09,320 --> 00:05:13,940
‫So I'm going to set death sound to explode audio here as well.

69
00:05:13,940 --> 00:05:21,200
‫So now we have sound assets and they're stored in variables both in our ponds and on the projectile.

70
00:05:21,200 --> 00:05:24,530
‫The only thing that's left is to actually play these sounds.

71
00:05:24,860 --> 00:05:28,550
‫Now you game play statics has another useful function.

72
00:05:28,550 --> 00:05:31,310
‫It's called play sound at location.

73
00:05:31,310 --> 00:05:37,370
‫Now we can scroll down and see that it takes quite a number of input parameters, but like most of these

74
00:05:37,370 --> 00:05:42,590
‫functions there are a number of optional parameters that have default values.

75
00:05:42,770 --> 00:05:45,680
‫So we can dig into the code to see this.

76
00:05:45,950 --> 00:05:51,410
‫So I'm going to hop into projectile CP and here and begin play.

77
00:05:51,410 --> 00:06:00,200
‫I'm going to type you gameplay statics, play sound at location and hit that opening parentheses there

78
00:06:00,200 --> 00:06:02,750
‫and I'll see that it says one of two.

79
00:06:03,020 --> 00:06:07,460
‫Now this first version it's showing me takes a world context object.

80
00:06:07,460 --> 00:06:09,830
‫We know we can pass this in for that.

81
00:06:09,830 --> 00:06:12,110
‫And next it takes a use sound base.

82
00:06:12,110 --> 00:06:17,810
‫So we have sound base variables and next it takes an F vector for the location.

83
00:06:17,810 --> 00:06:23,360
‫Now, if we want to play the sound at the location of the projectile, we can just use get actor location

84
00:06:23,360 --> 00:06:26,060
‫and the rest of these inputs are optional.

85
00:06:26,060 --> 00:06:32,420
‫So if you'd like to look into those, take another look at the documentation page for this function

86
00:06:32,420 --> 00:06:33,830
‫and do some more research.

87
00:06:33,830 --> 00:06:40,250
‫But we are only concerned with the first three inputs so we know how to play sounds at locations we

88
00:06:40,250 --> 00:06:40,970
‫can use you.

89
00:06:40,970 --> 00:06:47,870
‫Gameplay statics play sound at location, which takes a world context object, a sound which we can

90
00:06:47,870 --> 00:06:54,110
‫use our use sound base for and a location which we can use get actor location for.

91
00:06:54,110 --> 00:07:00,410
‫So your challenge will be to call play sound at location and play sounds for the various aspects of

92
00:07:00,410 --> 00:07:02,360
‫our gameplay that needs sounds.

93
00:07:02,360 --> 00:07:10,220
‫So call you gameplay statics play sound at location in the projectile class first in the on hit function

94
00:07:10,220 --> 00:07:12,500
‫and use our hit sound variable.

95
00:07:12,530 --> 00:07:18,830
‫Do this in the if check when we check to see if other actor is valid as well as make sure the other

96
00:07:18,830 --> 00:07:20,840
‫actor is not this or the owner.

97
00:07:20,840 --> 00:07:27,020
‫But call it before we destroy the projectile and call play sound at location and begin play for the

98
00:07:27,020 --> 00:07:29,630
‫projectile and use the launch sound.

99
00:07:29,630 --> 00:07:35,300
‫That way we'll get the sound played when the projectile gets spawned as well as when the projectile

100
00:07:35,330 --> 00:07:36,650
‫hits something next.

101
00:07:36,650 --> 00:07:42,110
‫Go into the base pong class and call play sound at location and handle destruction.

102
00:07:42,110 --> 00:07:43,730
‫And you're going to use the death sound.

103
00:07:43,730 --> 00:07:45,110
‫That's the explosion.

104
00:07:45,110 --> 00:07:50,000
‫So pause the video and add these calls to play sound at location now.

105
00:07:53,530 --> 00:07:53,800
‫Okay.

106
00:07:53,830 --> 00:07:59,470
‫So first we're here in Projectile CP and I'm going to go in order of the challenge.

107
00:07:59,470 --> 00:08:04,290
‫So first I'm going to go down to on hit and play the sound down here.

108
00:08:04,300 --> 00:08:11,440
‫Now you probably checked to see if the sound was null and if you did, I give you kudos because you're

109
00:08:11,440 --> 00:08:14,100
‫already getting those good programming habits.

110
00:08:14,110 --> 00:08:16,120
‫Now, if you didn't, that's okay.

111
00:08:16,150 --> 00:08:16,990
‫Go ahead and do it.

112
00:08:16,990 --> 00:08:17,290
‫Now.

113
00:08:17,290 --> 00:08:24,550
‫We're going to check to see if hit sound is valid before we call the new gameplay statics function.

114
00:08:24,550 --> 00:08:25,450
‫So it's going to be you.

115
00:08:25,450 --> 00:08:32,200
‫Gameplay statics play sound at location and we first need a world context object that's going to be

116
00:08:32,200 --> 00:08:32,650
‫this.

117
00:08:32,650 --> 00:08:37,660
‫Next we need the hit sound itself and we're going to play this at the actor location.

118
00:08:37,660 --> 00:08:42,670
‫So get actor location will satisfy that third parameter.

119
00:08:43,090 --> 00:08:44,260
‫Okay, perfect.

120
00:08:44,260 --> 00:08:47,170
‫Next, we need to play a sound and begin play.

121
00:08:47,170 --> 00:08:49,000
‫So let's go back up to begin play.

122
00:08:49,000 --> 00:08:54,010
‫And for this one, we're going to check to see if the launch sound is valid.

123
00:08:54,010 --> 00:09:02,500
‫So we're going to say if launch sound you game play statics play sound at location and of course we

124
00:09:02,500 --> 00:09:04,030
‫need the world context object.

125
00:09:04,030 --> 00:09:09,910
‫That's this the use sound base is going to be launch sound and we're going to play this at the actor

126
00:09:09,910 --> 00:09:10,570
‫location.

127
00:09:10,570 --> 00:09:17,140
‫So get actor location and that takes care of playing the sound and begin play.

128
00:09:17,140 --> 00:09:23,830
‫So the last thing to do is to play the sound on the base -- class and handle destruction.

129
00:09:23,830 --> 00:09:29,410
‫And now that we're handling visual and sound effects, we don't need to say to do here because we have

130
00:09:29,410 --> 00:09:30,100
‫done this.

131
00:09:30,100 --> 00:09:34,120
‫So first, we're going to check to see if death sound is valid.

132
00:09:34,120 --> 00:09:41,380
‫If it is, then we can call you gameplay statics play sound at location with the world context object.

133
00:09:41,380 --> 00:09:49,510
‫That's going to be this the sound base that's going to be death sound and get actor location will satisfy

134
00:09:49,540 --> 00:09:52,330
‫the location for this death sound.

135
00:09:52,450 --> 00:09:53,770
‫Ock Awesome.

136
00:09:53,770 --> 00:09:58,570
‫Let's go ahead and compile our code with a successful compile.

137
00:09:58,600 --> 00:10:02,200
‫We'll hop back here into the editor and let's play test this.

138
00:10:02,200 --> 00:10:05,590
‫So I'm going to hit play and wait for the timer.

139
00:10:14,030 --> 00:10:16,930
‫So in summary, we now have sound.

140
00:10:16,940 --> 00:10:23,540
‫We're playing a sound for the projectile on hit and on launch, and we're playing a sound for the pawn

141
00:10:23,540 --> 00:10:24,560
‫on death.

142
00:10:24,830 --> 00:10:30,560
‫So looking back at our section plan, we see that we've checked off just about every single item here.

143
00:10:30,560 --> 00:10:34,610
‫We're still on the special effects we got the smoke, the explosions and the sounds.

144
00:10:34,610 --> 00:10:40,850
‫There's just a few things to do to polish up this game and make sure it's looking and feeling right

145
00:10:40,850 --> 00:10:43,730
‫before we go ahead and wrap up this section.

146
00:10:43,730 --> 00:10:46,580
‫So I'll see you in the next video.

